diff --git a/api/org_tangled/actorgetProfileActivity.go b/api/org_tangled/actorgetProfileActivity.go index 05be44e21..2f9b144d9 100644 --- a/api/org_tangled/actorgetProfileActivity.go +++ b/api/org_tangled/actorgetProfileActivity.go @@ -42,10 +42,12 @@ type ActorGetProfileActivity_CommitRepoActivity struct { // ActorGetProfileActivity_IssueActivity is a "issueActivity" in the org.tangled.actor.getProfileActivity schema. type ActorGetProfileActivity_IssueActivity struct { - Repo *ActorGetProfileActivity_RepoRef `json:"repo" cborgen:"repo"` - State string `json:"state" cborgen:"state"` - Title string `json:"title" cborgen:"title"` - Uri string `json:"uri" cborgen:"uri"` + CommentCount int64 `json:"commentCount" cborgen:"commentCount"` + CreatedAt string `json:"createdAt" cborgen:"createdAt"` + Repo *ActorGetProfileActivity_RepoRef `json:"repo" cborgen:"repo"` + State string `json:"state" cborgen:"state"` + Title string `json:"title" cborgen:"title"` + Uri string `json:"uri" cborgen:"uri"` } // ActorGetProfileActivity_Output is the output of a org.tangled.actor.getProfileActivity call. @@ -57,10 +59,12 @@ type ActorGetProfileActivity_Output struct { // ActorGetProfileActivity_PullActivity is a "pullActivity" in the org.tangled.actor.getProfileActivity schema. type ActorGetProfileActivity_PullActivity struct { - Repo *ActorGetProfileActivity_RepoRef `json:"repo" cborgen:"repo"` - State string `json:"state" cborgen:"state"` - Title string `json:"title" cborgen:"title"` - Uri string `json:"uri" cborgen:"uri"` + CommentCount int64 `json:"commentCount" cborgen:"commentCount"` + CreatedAt string `json:"createdAt" cborgen:"createdAt"` + Repo *ActorGetProfileActivity_RepoRef `json:"repo" cborgen:"repo"` + State string `json:"state" cborgen:"state"` + Title string `json:"title" cborgen:"title"` + Uri string `json:"uri" cborgen:"uri"` } // ActorGetProfileActivity_RepoActivity is a "repoActivity" in the org.tangled.actor.getProfileActivity schema. diff --git a/bobbin/crates/xrpc/src/profile_activity.rs b/bobbin/crates/xrpc/src/profile_activity.rs index 2c51e17df..a846bbe3a 100644 --- a/bobbin/crates/xrpc/src/profile_activity.rs +++ b/bobbin/crates/xrpc/src/profile_activity.rs @@ -57,6 +57,8 @@ enum RawActivity { title: DefaultStr, state: DefaultStr, repo_did: Did, + comment_count: i64, + created_at: Datetime, }, Pull { months_ago: usize, @@ -64,6 +66,8 @@ enum RawActivity { title: DefaultStr, state: DefaultStr, repo_did: Did, + comment_count: i64, + created_at: Datetime, }, } @@ -214,6 +218,11 @@ async fn hydrate_activity( )); }; let title = title.text.clone(); + let comment_count = state.edges.count(&EdgeKey::new( + nsid_static("org.tangled.feed.comment"), + SubjectRef::Uri(uri.clone()), + )) as i64; + let created_at = record.created_at.clone(); Ok(if ticket_kind(&record) == TICKET_PULL_KIND { RawActivity::Pull { months_ago: item.months_ago, @@ -221,6 +230,8 @@ async fn hydrate_activity( title, state: record.state.clone(), repo_did, + comment_count, + created_at, } } else { RawActivity::Issue { @@ -229,6 +240,8 @@ async fn hydrate_activity( title, state: record.state.clone(), repo_did, + comment_count, + created_at, } }) } @@ -331,6 +344,8 @@ async fn assemble_months( title, state, repo_did, + comment_count, + created_at, } => { let Some(repo) = refs.get(repo_did.as_ref()) else { continue; @@ -340,6 +355,8 @@ async fn assemble_months( title, state, repo: repo.clone(), + comment_count, + created_at, extra_data: None, }); } @@ -349,6 +366,8 @@ async fn assemble_months( title, state, repo_did, + comment_count, + created_at, } => { let Some(repo) = refs.get(repo_did.as_ref()) else { continue; @@ -358,6 +377,8 @@ async fn assemble_months( title, state, repo: repo.clone(), + comment_count, + created_at, extra_data: None, }); } diff --git a/bobbin/crates/xrpc/tests/aggregation.rs b/bobbin/crates/xrpc/tests/aggregation.rs index 1c11d016b..1ce082248 100644 --- a/bobbin/crates/xrpc/tests/aggregation.rs +++ b/bobbin/crates/xrpc/tests/aggregation.rs @@ -11,7 +11,9 @@ use bobbin_resolver::RepoIdResolver; use bobbin_runtime::{RuntimeHasher, SystemClock, UnixMicros}; use bobbin_search::{DEFAULT_WRITER_HEAP_BYTES, SearchIndex, SearchReader}; use bobbin_slingshot_client::SlingshotClient; -use bobbin_types::edges::{Edge, TICKET_ISSUE_KIND, TICKET_PULL_KIND}; +use bobbin_types::edges::{ + Edge, TICKET_ISSUE_BY_KIND, TICKET_ISSUE_KIND, TICKET_PULL_BY_KIND, TICKET_PULL_KIND, +}; use bobbin_types::ids::SubjectRef; use bobbin_xrpc::{AppState, router}; use chrono::Utc; @@ -2181,6 +2183,47 @@ async fn profile_activity_returns_one_hydrated_aggregate() { }), ) .await; + for (by_kind, rk, body, comments) in [ + ( + TICKET_ISSUE_BY_KIND, + "issue1", + ticket_body("Activity panel overflows", "open"), + 2, + ), + ( + TICKET_PULL_BY_KIND, + "pull1", + pull_body("Add the activity panel", "completed"), + 1, + ), + ] { + let ticket_uri = at(&format!( + "at://{}/org.tangled.track.ticket/{rk}", + created_repo_did.as_ref(), + )); + h.edges.add(Edge { + kind: nsid(by_kind), + subject: SubjectRef::Did(actor.clone()), + source: ticket_uri.clone(), + sort_micros: event_micros, + }); + h.mount( + &created_repo_did, + &nsid("org.tangled.track.ticket"), + &rkey(rk), + body, + ) + .await; + for index in 0..comments { + h.add_edge( + &nsid("org.tangled.feed.comment"), + &ticket_uri, + &at(&format!( + "at://did:plc:olaren/org.tangled.feed.comment/{rk}c{index}" + )), + ); + } + } let (status, body) = json_response( router(h.state.clone()) .oneshot( @@ -2213,8 +2256,16 @@ async fn profile_activity_returns_one_hydrated_aggregate() { commit_repos[0]["recent"][0]["subject"], "Add the activity panel" ); - assert_eq!(months[0]["issues"], json!([]), "tickets are repo-owned"); - assert_eq!(months[0]["pulls"], json!([]), "tickets are repo-owned"); + let issue = &months[0]["issues"][0]; + assert_eq!(issue["title"], "Activity panel overflows"); + assert_eq!(issue["repo"]["name"], "fresh"); + assert_eq!(issue["commentCount"], 2); + assert_eq!(issue["createdAt"], "2026-05-01T00:00:00Z"); + let pull = &months[0]["pulls"][0]; + assert_eq!(pull["title"], "Add the activity panel"); + assert_eq!(pull["state"], "completed"); + assert_eq!(pull["commentCount"], 1); + assert_eq!(pull["createdAt"], "2026-05-01T00:00:00Z"); } #[tokio::test] diff --git a/lexicons/org/tangled/actor/getProfileActivity.json b/lexicons/org/tangled/actor/getProfileActivity.json index e554dfdda..4684ed062 100644 --- a/lexicons/org/tangled/actor/getProfileActivity.json +++ b/lexicons/org/tangled/actor/getProfileActivity.json @@ -202,7 +202,9 @@ "uri", "title", "state", - "repo" + "repo", + "commentCount", + "createdAt" ], "properties": { "uri": { @@ -223,6 +225,14 @@ "repo": { "type": "ref", "ref": "#repoRef" + }, + "commentCount": { + "type": "integer", + "minimum": 0 + }, + "createdAt": { + "type": "string", + "format": "datetime" } } }, @@ -232,7 +242,9 @@ "uri", "title", "state", - "repo" + "repo", + "commentCount", + "createdAt" ], "properties": { "uri": { @@ -253,6 +265,14 @@ "repo": { "type": "ref", "ref": "#repoRef" + }, + "commentCount": { + "type": "integer", + "minimum": 0 + }, + "createdAt": { + "type": "string", + "format": "datetime" } } } diff --git a/web/src/lib/api/lexicons/types/org/tangled/actor/getProfileActivity.ts b/web/src/lib/api/lexicons/types/org/tangled/actor/getProfileActivity.ts index 0c47245c7..db90f314f 100644 --- a/web/src/lib/api/lexicons/types/org/tangled/actor/getProfileActivity.ts +++ b/web/src/lib/api/lexicons/types/org/tangled/actor/getProfileActivity.ts @@ -72,6 +72,11 @@ const _issueActivitySchema = /*#__PURE__*/ v.object({ "org.tangled.actor.getProfileActivity#issueActivity", ), ), + /** + * @minimum 0 + */ + commentCount: /*#__PURE__*/ v.integer(), + createdAt: /*#__PURE__*/ v.datetimeString(), get repo() { return repoRefSchema; }, @@ -120,6 +125,11 @@ const _pullActivitySchema = /*#__PURE__*/ v.object({ "org.tangled.actor.getProfileActivity#pullActivity", ), ), + /** + * @minimum 0 + */ + commentCount: /*#__PURE__*/ v.integer(), + createdAt: /*#__PURE__*/ v.datetimeString(), get repo() { return repoRefSchema; }, diff --git a/web/src/lib/components/profile/ActivityMonthPanel.svelte b/web/src/lib/components/profile/ActivityMonthPanel.svelte index a39a33535..c09fbdcd4 100644 --- a/web/src/lib/components/profile/ActivityMonthPanel.svelte +++ b/web/src/lib/components/profile/ActivityMonthPanel.svelte @@ -6,9 +6,12 @@ import BookPlus from "$icon/book-plus"; import ChevronRight from "$icon/chevron-right"; import CircleDot from "$icon/circle-dot"; + import CirclePlus from "$icon/circle-plus"; import GitCommit from "$icon/git-commit-horizontal"; + import GitFork from "$icon/git-fork"; import GitPullRequest from "$icon/git-pull-request"; import Avatar from "#lib/components/ui/Avatar.svelte"; + import Button from "#lib/components/ui/Button.svelte"; import EmptyState from "#lib/components/ui/EmptyState.svelte"; import ActivityTicket from "#lib/components/profile/ActivityTicket.svelte"; import { pluralize } from "#lib/format.ts"; @@ -23,38 +26,45 @@ month, open, id, + order, + expanded = $bindable(), focus = null }: { month: ProfileActivityMonth | null; open: boolean; id: string; - focus?: { metric: ActivityMetric } | null; + order: ActivityMetric[]; + expanded: Partial>; + focus?: { metric: ActivityMetric | null } | null; } = $props(); const SLIDE_DISTANCE = 12; const SLIDE_DURATION = 200; - let expanded = $state>>({}); let region = $state(); let previous: number | null = null; const reduceMotion = () => matchMedia("(prefers-reduced-motion: reduce)").matches; + const sectionOf = (metric: ActivityMetric) => + document.getElementById(`${id}-${metric}-section`); + + const reveal = async (target: () => HTMLElement | null | undefined) => { + await tick(); + if (!region) return; + await Promise.allSettled( + region.getAnimations({ subtree: true }).map((animation) => animation.finished) + ); + target()?.scrollIntoView({ + block: "nearest", + behavior: reduceMotion() ? "auto" : "smooth" + }); + }; + $effect(() => { if (!focus) return; const { metric } = focus; - expanded = { [metric]: true }; - tick().then(async () => { - const section = document.getElementById(`${id}-${metric}-section`); - if (!region || !section) return; - await Promise.allSettled( - region.getAnimations({ subtree: true }).map((animation) => animation.finished) - ); - section.scrollIntoView({ - block: "nearest", - behavior: reduceMotion() ? "auto" : "smooth" - }); - }); + void reveal(() => (metric ? sectionOf(metric) : region)); }); const slideIn = @@ -91,13 +101,19 @@ {#snippet repoName(repo: ActivityRepoRef)} - - + {repo.ownerHandle}/{repo.name} - + {/snippet}
{#if month} @@ -119,15 +135,27 @@ {@const pullGroups = groupByRepo(current.pulls)} {#snippet reposBody()} -
    +
      {#each current.repos as repo (repoKey(repo))}
    • - + {@render repoName(repo)} - {repo.forked ? "Forked" : "Created"} + + {#if repo.forked} + {#if repo.description} -

      {repo.description}

      +

      + {repo.description} +

      {/if}
    • {/each} @@ -138,16 +166,18 @@ kind: "issues" | "pulls", groups: typeof issueGroups | typeof pullGroups )} - {#each groups as group (repoKey(group.repo))} -
      - {@render repoName(group.repo)} -
        - {#each group.items as ticket (ticket.uri)} -
      • - {/each} -
      -
      - {/each} +
      + {#each groups as group (repoKey(group.repo))} +
      + {@render repoName(group.repo)} +
        + {#each group.items as ticket (ticket.uri)} +
      • + {/each} +
      +
      + {/each} +
      {/snippet} {#snippet pullsBody()} @@ -159,16 +189,13 @@ {/snippet} {#snippet commitsBody()} -
        + @@ -217,14 +244,21 @@ body: commitsBody } ] satisfies Section[] - ).filter((section) => - section.key === "commits" ? current.commits > 0 : current[section.key].length > 0 - )} + ) + .filter((section) => + section.key === "commits" + ? current.commits > 0 + : current[section.key].length > 0 + ) + .toSorted((a, b) => order.indexOf(a.key) - order.indexOf(b.key))}
        +

        + {formatMonth(current.monthsAgo, { month: "long" })} +

        {#if sections.length > 0}
          {#each sections as section, index (section.key)} @@ -242,20 +276,28 @@ {/if} diff --git a/web/src/lib/components/profile/ProfileActivityChart.stories.svelte b/web/src/lib/components/profile/ProfileActivityChart.stories.svelte index df04efae6..b1fd78f76 100644 --- a/web/src/lib/components/profile/ProfileActivityChart.stories.svelte +++ b/web/src/lib/components/profile/ProfileActivityChart.stories.svelte @@ -80,7 +80,11 @@ rkey: `3mi${monthsAgo}${n}`, title: pick(issueTitles, monthsAgo * 3 + n), state: n % 3 === 2 ? ("closed" as const) : ("open" as const), - repo: pick(repos, monthsAgo + n * 2) + repo: pick(repos, monthsAgo + n * 2), + commentCount: (monthsAgo * 7 + n * 5) % 13, + createdAt: new Date( + Date.UTC(2026, 9 - monthsAgo, 26 - ((n * 3) % 24), 9 + (n % 8)) + ).toISOString() })), pulls: Array.from({ length: month.pulls }, (_, n) => ({ uri: `at://did:plc:alice/sh.tangled.repo.pull/3mp${monthsAgo}${n}`, @@ -92,7 +96,11 @@ : n % 3 === 1 ? ("open" as const) : ("merged" as const), - repo: pick(repos, (n * n + monthsAgo) % 4) + repo: pick(repos, (n * n + monthsAgo) % 4), + commentCount: (monthsAgo * 3 + n * n) % 17, + createdAt: new Date( + Date.UTC(2026, 9 - monthsAgo, 27 - ((n * 2) % 25), 11 + (n % 9)) + ).toISOString() })) }; }), @@ -124,6 +132,13 @@ months: activity.months.filter((month) => month.monthsAgo === 4 || month.monthsAgo === 1) }; + const twoMonthsAgo = (() => { + const now = new Date(); + return new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth() - 2, 1)) + .toISOString() + .slice(0, 7); + })(); + const { Story } = defineMeta({ title: "Profile/ProfileActivityChart", component: ProfileActivityChart, @@ -139,6 +154,27 @@ }} /> + { + const canvas = within(canvasElement); + const months = canvas.getAllByRole("button", { name: / activity$/ }); + await expect(months[3]).toHaveAttribute("aria-pressed", "true"); + const region = canvas.getByRole("region"); + await expect(region).not.toHaveAttribute("inert"); + await expect( + within(region).getByRole("button", { name: /pull requests in/ }) + ).toHaveAttribute("aria-expanded", "true"); + }} +/> + { @@ -150,12 +186,12 @@ await expect(region).not.toHaveAttribute("inert"); const month = activity.months[0]; const sections = [...region.querySelectorAll("ol > li")]; - await expect(sections.map((section) => section.id.split("-").at(-2))).toEqual([ - "repos", - "pulls", - "issues", - "commits" - ]); + const points = [ + ...canvasElement.querySelectorAll('[data-metric][data-month="0"]') + ].toSorted((a, b) => parseFloat(a.style.top) - parseFloat(b.style.top)); + await expect(sections.map((section) => section.id.split("-").at(-2))).toEqual( + points.map((point) => point.dataset.metric) + ); const pulls = within(region).getByRole("button", { name: /pull requests in/ }); await expect(pulls).toHaveAttribute("aria-expanded", "false"); await userEvent.click(pulls); @@ -164,10 +200,10 @@ month.pulls.length ); await userEvent.click(within(region).getByRole("button", { name: /commits in/ })); - await expect( - region.querySelectorAll(`[id$="-commits"] a[href$="/commits/HEAD"]`) - ).toHaveLength(month.commitRepos.length); - await expect(region.querySelector('[id$="-commits"] a[href*="/commit/"]')).toBeNull(); + await expect(region.querySelectorAll('[id$="-commits"] a')).toHaveLength( + month.commitRepos.length + ); + await expect(region.querySelector('[id$="-commits"] a[href*="/commit"]')).toBeNull(); }} /> @@ -188,6 +224,13 @@ "aria-expanded", "false" ); + await userEvent.click( + canvasElement.querySelector('[data-metric="issues"][data-month="0"]')! + ); + await expect(within(region).getByRole("button", { name: /issues in/ })).toHaveAttribute( + "aria-expanded", + "false" + ); }} /> @@ -223,6 +266,10 @@ await userEvent.hover(count); await expect(line("pulls")).toHaveAttribute("stroke-opacity", "0.9"); await expect(line("commits")).toHaveAttribute("stroke-opacity", "0.08"); + await expect(count).toHaveClass("text-foreground-default"); + await expect( + canvasElement.querySelector('[data-metric="commits"][data-month="2"]') + ).toHaveClass("text-foreground-subtle"); await userEvent.unhover(count); await expect(line("pulls")).toHaveAttribute("stroke-opacity", "0.25"); }} @@ -240,7 +287,7 @@ await expect(within(current).getByText(/./)).toHaveClass("text-foreground-muted"); await expect( canvasElement.querySelector('[data-metric="commits"][data-month="5"]') - ).toHaveClass("text-foreground-muted"); + ).toHaveClass("text-foreground-default"); }} /> diff --git a/web/src/lib/components/profile/ProfileActivityChart.svelte b/web/src/lib/components/profile/ProfileActivityChart.svelte index 9c3812a31..e27e9debe 100644 --- a/web/src/lib/components/profile/ProfileActivityChart.svelte +++ b/web/src/lib/components/profile/ProfileActivityChart.svelte @@ -2,6 +2,9 @@ import type { Action } from "svelte/action"; import type { Component } from "svelte"; import type { SvelteHTMLElements } from "svelte/elements"; + import { goto } from "$app/navigation"; + import { page } from "$app/state"; + import { resolve } from "$app/paths"; import BookPlus from "$icon/book-plus"; import CircleDot from "$icon/circle-dot"; import GitCommit from "$icon/git-commit-horizontal"; @@ -9,7 +12,7 @@ import EmptyState from "#lib/components/ui/EmptyState.svelte"; import ActivityMonthPanel from "#lib/components/profile/ActivityMonthPanel.svelte"; import { formatCount, plural } from "#lib/format.ts"; - import { formatMonth } from "#lib/components/profile/activityMonths.ts"; + import { formatMonth, monthStart } from "#lib/components/profile/activityMonths.ts"; import { remToPx } from "#lib/rem.ts"; import { ACTIVITY_METRICS, @@ -28,6 +31,8 @@ const uid = $props.id(); const panelId = `${uid}-month`; + const MONTH_PARAM = "month"; + const SECTION_PARAM = "section"; const MONTH_COUNT = 6; const CURRENT_MONTH = MONTH_COUNT - 1; @@ -49,6 +54,7 @@ }) ); const monthName = (monthsAgo: number) => formatMonth(monthsAgo, { month: "long" }); + const monthKey = (monthsAgo: number) => monthStart(monthsAgo).toISOString().slice(0, 7); const metrics: { key: ActivityMetric; label: string; singular: string; icon: Icon }[] = [ { key: "pulls", label: "pull requests", singular: "pull request", icon: GitPullRequest }, { key: "commits", label: "commits", singular: "commit", icon: GitCommit }, @@ -102,19 +108,67 @@ }; }; - let selected = $state(null); + const fromUrl = () => { + const params = page.url.searchParams; + const index = months.findIndex( + (month) => monthKey(month.monthsAgo) === params.get(MONTH_PARAM) + ); + if (index === -1) return { selected: null, expanded: {} }; + return { + selected: index, + expanded: Object.fromEntries( + params + .getAll(SECTION_PARAM) + .filter((key) => ACTIVITY_METRICS.includes(key as ActivityMetric)) + .map((key) => [key, true]) + ) + }; + }; + const initial = fromUrl(); + let selected = $state(initial.selected); const activeMonth = $derived(selected ?? CURRENT_MONTH); - let shown = $state(null); + let shown = $state(initial.selected); + let focus = $state<{ metric: ActivityMetric | null } | null>(null); const select = (monthIndex: number) => { selected = selected === monthIndex ? null : monthIndex; - if (selected !== null) shown = selected; + if (selected === null) return; + shown = selected; + focus = { metric: null }; }; - let focus = $state<{ metric: ActivityMetric } | null>(null); + let expanded = $state>>(initial.expanded); + $effect(() => { + const current = page.shallow?.url ?? page.url; + const url = new URL(current.href); + url.searchParams.delete(MONTH_PARAM); + url.searchParams.delete(SECTION_PARAM); + if (selected !== null) { + url.searchParams.set(MONTH_PARAM, monthKey(months[selected].monthsAgo)); + for (const metric of ACTIVITY_METRICS) + if (expanded[metric]) url.searchParams.append(SECTION_PARAM, metric); + } + if (url.href !== current.href) + void goto(resolve((url.pathname + url.search) as "/"), { + shallow: true, + replace: true + }); + }); const openPoint = (monthIndex: number, metric: ActivityMetric) => { + if (selected === monthIndex && expanded[metric]) { + expanded[metric] = false; + return; + } selected = monthIndex; shown = monthIndex; + expanded = { [metric]: true }; focus = { metric }; }; + const order = $derived( + shown === null + ? [...ACTIVITY_METRICS] + : ACTIVITY_METRICS.toSorted( + (a, b) => layout.points[a][shown!].y - layout.points[b][shown!].y + ) + ); let hoveredMetric = $state(null); @@ -130,7 +184,9 @@ class="rounded-md border border-border-default transition-[border-radius] duration-250 ease-out-strong {selected === null ? '' - : 'rounded-b-none'} {measured ? 'overflow-x-auto' : 'overflow-hidden'}" + : 'rounded-b-none border-b-transparent bg-background-subtle'} {measured + ? 'overflow-x-auto' + : 'overflow-hidden'}" >
          {/each} @@ -227,6 +299,8 @@ id={panelId} month={shown === null ? null : months[shown]} open={selected !== null} + {order} + bind:expanded {focus} />
        diff --git a/web/src/lib/components/profile/ProfileChrome.stories.svelte b/web/src/lib/components/profile/ProfileChrome.stories.svelte index 76456c7a0..c9b01c27f 100644 --- a/web/src/lib/components/profile/ProfileChrome.stories.svelte +++ b/web/src/lib/components/profile/ProfileChrome.stories.svelte @@ -107,7 +107,11 @@ ownerDid: "did:plc:tangled", ownerHandle: "tangled.org", name: "core" - } + }, + commentCount: (monthsAgo * 4 + issue * 3) % 9, + createdAt: new Date( + Date.UTC(2026, 9 - monthsAgo, 22 - issue * 2, 13) + ).toISOString() })), pulls: Array.from({ length: month.pulls }, (_, pull) => ({ uri: `at://${identity.did}/sh.tangled.repo.pull/3mp${monthsAgo}${pull}`, @@ -119,7 +123,9 @@ ownerDid: "did:plc:tangled", ownerHandle: "tangled.org", name: "core" - } + }, + commentCount: (monthsAgo * 3 + pull * pull) % 12, + createdAt: new Date(Date.UTC(2026, 9 - monthsAgo, 26 - pull, 16)).toISOString() })) }; }), @@ -131,7 +137,7 @@ canvas.getByRole("heading", { name: `${identity.handle} ${profile.pronouns}` }) ).toBeVisible(); await expect(canvas.getByRole("heading", { name: "Activity" })).toBeVisible(); - await expect(canvas.getByText("1.3k")).toHaveTextContent("1.3k commits"); + await expect(canvas.getByText("1.3k commits")).toBeVisible(); await expect(canvas.getByRole("heading", { name: "Pinned repositories" })).toBeVisible(); }; const organizationOverview = async ({ canvas }: PlayContext) => { diff --git a/web/src/lib/components/profile/activityPullStat.ts b/web/src/lib/components/profile/activityPullStat.ts new file mode 100644 index 000000000..382f63c31 --- /dev/null +++ b/web/src/lib/components/profile/activityPullStat.ts @@ -0,0 +1,28 @@ +import type { Did } from "@atcute/lexicons"; +import { createBobbinClient } from "#lib/api/client.ts"; +import type { DiffStat } from "#lib/api/diff.ts"; +import { listPatches } from "#lib/api/records.ts"; +import { loadDiffStat } from "#lib/api/repoDiff.ts"; +import type { ActivityPull } from "#lib/components/profile/types.ts"; + +const STAT_TIMEOUT_MS = 5_000; +const STAT_MAX_BYTES = 1024 * 1024; + +export const loadPullStat = async ( + bobbinUrl: string, + pull: ActivityPull +): Promise => { + const patches = await listPatches( + createBobbinClient({ serviceUrl: bobbinUrl }), + pull.uri + ).catch(() => undefined); + const latest = patches?.items.at(-1)?.value; + if (!latest) return undefined; + return loadDiffStat( + { bobbinUrl, ssrDiffMaxBytes: STAT_MAX_BYTES }, + pull.repo.repoDid as Did, + { base: latest.base.oid, head: latest.head.oid, repo: latest.source?.repo }, + fetch, + STAT_TIMEOUT_MS + ); +}; diff --git a/web/src/lib/components/profile/pages.test.ts b/web/src/lib/components/profile/pages.test.ts index ff1201658..381d63615 100644 --- a/web/src/lib/components/profile/pages.test.ts +++ b/web/src/lib/components/profile/pages.test.ts @@ -597,6 +597,8 @@ describe("fetchProfileActivity", () => { uri: "at://did:plc:alice/sh.tangled.repo.issue/open", title: "Open issue", state: "open", + commentCount: 4, + createdAt: "2026-09-03T08:15:00Z", repo: { uri: "at://did:plc:bob/sh.tangled.repo/target", did: "did:plc:target", @@ -611,6 +613,8 @@ describe("fetchProfileActivity", () => { uri: "at://did:plc:alice/sh.tangled.repo.pull/merged", title: "Merged pull", state: "merged", + commentCount: 0, + createdAt: "2026-08-28T17:40:00Z", repo: { uri: "at://did:plc:bob/sh.tangled.repo/target", did: "did:plc:target", @@ -650,6 +654,8 @@ describe("fetchProfileActivity", () => { uri: "at://did:plc:alice/sh.tangled.repo.issue/closed", title: "Closed issue", state: "closed", + commentCount: 11, + createdAt: "2026-03-12T09:05:00Z", repo: { uri: "at://did:plc:bob/sh.tangled.repo/target", did: "did:plc:target", @@ -713,6 +719,8 @@ describe("fetchProfileActivity", () => { { rkey: "open", state: "open", + commentCount: 4, + createdAt: "2026-09-03T08:15:00Z", repo: { repoDid: "did:plc:target", ownerDid: "did:plc:bob", @@ -721,8 +729,12 @@ describe("fetchProfileActivity", () => { } } ]); - expect(activity.months[0].pulls).toMatchObject([{ rkey: "merged", state: "merged" }]); - expect(activity.months[2].issues).toMatchObject([{ rkey: "closed", state: "closed" }]); + expect(activity.months[0].pulls).toMatchObject([ + { rkey: "merged", state: "merged", commentCount: 0, createdAt: "2026-08-28T17:40:00Z" } + ]); + expect(activity.months[2].issues).toMatchObject([ + { rkey: "closed", state: "closed", commentCount: 11, createdAt: "2026-03-12T09:05:00Z" } + ]); }); }); diff --git a/web/src/lib/components/profile/pages.ts b/web/src/lib/components/profile/pages.ts index 8841f418b..b4797e243 100644 --- a/web/src/lib/components/profile/pages.ts +++ b/web/src/lib/components/profile/pages.ts @@ -673,14 +673,18 @@ export const fetchProfileActivity = async ( rkey: rkeyFromUri(item.uri), title: item.title, state: item.state === "closed" ? "closed" : "open", - repo: activityRepoRef(item.repo, did, profileHandle) + repo: activityRepoRef(item.repo, did, profileHandle), + commentCount: item.commentCount, + createdAt: item.createdAt })), pulls: month.pulls.map((item) => ({ uri: item.uri, rkey: rkeyFromUri(item.uri), title: item.title, state: activityPullState(item.state), - repo: activityRepoRef(item.repo, did, profileHandle) + repo: activityRepoRef(item.repo, did, profileHandle), + commentCount: item.commentCount, + createdAt: item.createdAt })) } ]; diff --git a/web/src/lib/components/profile/tabs/OverviewTab.stories.svelte b/web/src/lib/components/profile/tabs/OverviewTab.stories.svelte index 6d1a9c6ee..982a7d2ed 100644 --- a/web/src/lib/components/profile/tabs/OverviewTab.stories.svelte +++ b/web/src/lib/components/profile/tabs/OverviewTab.stories.svelte @@ -45,7 +45,9 @@ ownerDid: "did:plc:tangled", ownerHandle: "tangled.org", name: "core" - } + }, + commentCount: (monthsAgo * 5 + index * 3) % 11, + createdAt: new Date(Date.UTC(2026, 9 - monthsAgo, 24 - index * 3, 10)).toISOString() })); const pullRefs = (monthsAgo: number, count: number): ActivityPull[] => Array.from({ length: count }, (_, index) => ({ @@ -64,7 +66,9 @@ ownerDid: "did:plc:tangled", ownerHandle: "tangled.org", name: "core" - } + }, + commentCount: (monthsAgo * 2 + index * index) % 14, + createdAt: new Date(Date.UTC(2026, 9 - monthsAgo, 25 - index * 2, 15)).toISOString() })); const activityShape = [ { commits: 341, repos: 2, issues: 4, pulls: 9 }, diff --git a/web/src/lib/components/profile/types.ts b/web/src/lib/components/profile/types.ts index d448b96af..be82a3837 100644 --- a/web/src/lib/components/profile/types.ts +++ b/web/src/lib/components/profile/types.ts @@ -137,6 +137,8 @@ export interface ActivityIssue { title: string; state: "open" | "closed"; repo: ActivityRepoRef; + commentCount: number; + createdAt: string; } export interface ActivityPull { @@ -145,6 +147,8 @@ export interface ActivityPull { title: string; state: "open" | "closed" | "merged"; repo: ActivityRepoRef; + commentCount: number; + createdAt: string; } export interface ProfileActivityMonth { diff --git a/web/src/lib/components/ui/Hovercard.svelte b/web/src/lib/components/ui/Hovercard.svelte index 9bef9d704..60d77594d 100644 --- a/web/src/lib/components/ui/Hovercard.svelte +++ b/web/src/lib/components/ui/Hovercard.svelte @@ -232,7 +232,14 @@ > {#if mounted}
        - {@render content()} + + {@render content()} + {#snippet failed()} +

        + Couldn't show this preview. +

        + {/snippet} +
        {/if}