Something went wrong. Try again.
Monorepo for Tangled
Something went wrong. Try again.
Svelte
at sl/gitmirror
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109<script lang="ts"> import type { Snippet } from "svelte"; import { setContext } from "svelte"; import { createBobbinClient } from "$lib/api/client"; import { IdentityCache } from "$lib/api/identity"; import { getAuth } from "$lib/auth.svelte"; import type { ProfileRecord } from "$lib/api/records"; import EmptyState from "$lib/components/ui/EmptyState.svelte"; import { createProfileCounts, PROFILE_COUNTS_KEY } from "$lib/components/profile/counts.svelte"; import { resolveVouches } from "$lib/components/profile/pages"; import { networkVouchesFor } from "$lib/components/profile/vouchBadge.svelte"; import { directVouch } from "$lib/components/profile/vouchRelationship"; import OrganizationChrome from "$lib/components/profile/organization/OrganizationChrome.svelte"; import UserProfileChrome from "$lib/components/profile/UserProfileChrome.svelte"; import type { DirectVouch, NetworkVouch, ProfileCounts } from "$lib/components/profile/types";
interface Props { identity: { did: string; handle: string }; profile: ProfileRecord | null; loadedCounts: ProfileCounts; viewerFollowRkey?: string | null; notJoined: boolean; bobbinUrl: string; delegationDid?: string; activeTab: string; content: Snippet; }
let { identity, profile, loadedCounts, viewerFollowRkey, notJoined, bobbinUrl, delegationDid, activeTab, content }: Props = $props();
// setContext refuses to run after an await, so the shell awaits the props first const profileCounts = createProfileCounts( () => identity.did, () => loadedCounts ); setContext(PROFILE_COUNTS_KEY, profileCounts); const counts = $derived(profileCounts.value);
// network vouches need the viewer's oauth agent, which only lives in the browser const auth = getAuth(); let networkVouches = $state<NetworkVouch[]>([]); let viewerVouch = $state<DirectVouch | null>(null);
$effect(() => { if (profile?.isOrganization) return; const agent = auth.agent; const did = identity.did; const viewerDid = auth.currentDid; networkVouches = []; viewerVouch = null; if (!agent || !viewerDid) return;
let cancelled = false; const cache = new IdentityCache(createBobbinClient({ serviceUrl: bobbinUrl })); networkVouchesFor(auth, did) .then(async (items) => { const resolved = await resolveVouches([...items], did, cache); if (cancelled) return; viewerVouch = directVouch({ viewer: viewerDid, actor: did, vouches: items }); networkVouches = resolved .filter((v) => v.direction === "incoming" && v.did !== viewerDid) .map((v) => ({ did: v.did, handle: v.handle, kind: v.kind })); }) .catch(() => { if (!cancelled) networkVouches = []; }); return () => { cancelled = true; }; });</script>
{#if notJoined} <EmptyState message={`${identity.handle} hasn't joined Tangled yet.`} />{:else} {#if profile?.isOrganization} <OrganizationChrome {identity} {profile} {counts} {viewerFollowRkey} {delegationDid} {activeTab} {content} /> {:else} <UserProfileChrome {identity} {profile} {counts} {viewerFollowRkey} {viewerVouch} {networkVouches} {activeTab} {content} /> {/if}{/if}