diff --git a/web/src/lib/components/profile/pages.test.ts b/web/src/lib/components/profile/pages.test.ts index 9505d96e..97482582 100644 --- a/web/src/lib/components/profile/pages.test.ts +++ b/web/src/lib/components/profile/pages.test.ts @@ -1,5 +1,6 @@ import { describe, expect, it, vi } from "vitest"; import { createBobbinClient } from "$lib/api/client"; +import { TYPE_MINIDOC } from "$lib/api/enrich"; import { fetchPeoplePage, fetchPinned, fetchReposPage, fetchStarredPage } from "./pages"; const enriched = () => Response.json({ output: { items: [], hits: [] }, data: {} }); @@ -136,6 +137,7 @@ describe("fetchStarredPage", () => { await fetchPinned(ctx, { keys: ["did:plc:repo", "at://did:plc:alice/sh.tangled.repo/example"], + did: "did:plc:alice", handle: "alice.test", viewerDid: "did:plc:viewer" }); @@ -147,7 +149,11 @@ describe("fetchStarredPage", () => { ]); expect( bodies.every((body) => - body.enrich.every((descriptor) => descriptor.targets?.[0] === "items[].value.repoDid") + body.enrich.every((descriptor) => + descriptor.type === TYPE_MINIDOC + ? descriptor.targets?.[0] === "items[].uri" + : descriptor.targets?.[0] === "items[].value.repoDid" + ) ) ).toBe(true); }); diff --git a/web/src/lib/components/profile/pages.ts b/web/src/lib/components/profile/pages.ts index e787c138..465d99a6 100644 --- a/web/src/lib/components/profile/pages.ts +++ b/web/src/lib/components/profile/pages.ts @@ -425,6 +425,7 @@ export const fetchProfileCard = async ( export interface PinnedOptions { keys: readonly string[]; + did: string; handle: string; viewerDid?: string; } @@ -434,8 +435,13 @@ export interface PinnedOptions { // hydrate export const fetchPinned = async ( ctx: BobbinContext, - { keys, handle, viewerDid }: PinnedOptions + { keys, did, handle, viewerDid }: PinnedOptions ): Promise => { + const ownerHandleOf = (item: ListItem, data: Sidecar): string => { + const owner = authorOf(data, item.uri, REPO_OWNER_DOCS); + const resolved = owner.did === did ? handle : owner.handle; + return resolved.endsWith(".invalid") ? owner.did : resolved; + }; const dids = keys.filter((key) => key.startsWith("did:")); const uris = keys.filter((key) => key.startsWith("at://")); const [byDid, byUri] = await Promise.all([ @@ -443,7 +449,10 @@ export const fetchPinned = async ( ? enrich<{ items: ListItem[] }>(ctx, { xrpc: "sh.tangled.repo.getReposByRepoDids", params: { dids }, - enrich: targetAll(REPO_STATS, ["items[].value.repoDid"]), + enrich: [ + ...targetAll(REPO_STATS, ["items[].value.repoDid"]), + target(REPO_OWNER_DOCS, ["items[].uri"]) + ], viewer: viewerDid }) : emptyItems(), @@ -451,7 +460,10 @@ export const fetchPinned = async ( ? enrich<{ items: ListItem[] }>(ctx, { xrpc: "sh.tangled.repo.getRepos", params: { repos: uris }, - enrich: targetAll(REPO_STATS, ["items[].value.repoDid"]), + enrich: [ + ...targetAll(REPO_STATS, ["items[].value.repoDid"]), + target(REPO_OWNER_DOCS, ["items[].uri"]) + ], viewer: viewerDid }) : emptyItems() @@ -459,10 +471,11 @@ export const fetchPinned = async ( const cards = new Map(); for (const item of byDid.output.items) { const repoDid = (item.value as RepoRecord).repoDid; - if (repoDid) cards.set(repoDid, resolveRepoCard(item, handle, byDid.data)); + if (repoDid) + cards.set(repoDid, resolveRepoCard(item, ownerHandleOf(item, byDid.data), byDid.data)); } for (const item of byUri.output.items) { - cards.set(item.uri, resolveRepoCard(item, handle, byUri.data)); + cards.set(item.uri, resolveRepoCard(item, ownerHandleOf(item, byUri.data), byUri.data)); } return keys .map((key) => cards.get(key)) diff --git a/web/src/lib/components/profile/tabs/OverviewTab.svelte b/web/src/lib/components/profile/tabs/OverviewTab.svelte index e4884a6f..6a6e42f3 100644 --- a/web/src/lib/components/profile/tabs/OverviewTab.svelte +++ b/web/src/lib/components/profile/tabs/OverviewTab.svelte @@ -6,9 +6,10 @@ interface Props { pinned: RepoCardData[]; + handle: string; } - let { pinned }: Props = $props(); + let { pinned, handle }: Props = $props();
@@ -19,7 +20,7 @@ emptyMessage="No pinned repositories." > {#each pinned as repo (repoKey(repo))} - + {/each}
diff --git a/web/src/routes/[handle]/+page.svelte b/web/src/routes/[handle]/+page.svelte index f9f915c7..e0644664 100644 --- a/web/src/routes/[handle]/+page.svelte +++ b/web/src/routes/[handle]/+page.svelte @@ -10,7 +10,7 @@ {#if data.tab === "overview"} - + {:else if data.tab === "repos"} {#key data.repos} { default: { const pinned = await fetchPinned(ctx, { keys: parent.profile?.pinnedRepositories ?? [], + did, handle, viewerDid });