fix pfp on account switcher not loading on load
1 unmodified line234566789101 unmodified linesExpand all11111211311411611711511811912011611711811960 unmodified lines1 unmodified line import { loggingIn, type Account } from '$lib/accounts'; import { AtpClient, resolveHandle } from '$lib/at/client.svelte'; import type { Handle } from '@atcute/lexicons'; import ProfilePicture from './ProfilePicture.svelte'; import PfpPlaceholder from './PfpPlaceholder.svelte'; import Popup from './Popup.svelte'; import Dropdown from './Dropdown.svelte'; import AccountSelector from './AccountSelector.svelte'; import { flow } from '$lib/at/oauth';101 unmodified linesExpand all <button onclick={toggleDropdown} class="flex h-13 w-13 items-center justify-center rounded-sm shadow-md transition-all hover:scale-110 hover:shadow-xl hover:saturate-150" > {#if selectedDid} <ProfilePicture {client} did={selectedDid} size={13} /> <ProfilePicture {client} did={selectedDid} size={13} /> {:else} <PfpPlaceholder color="var(--nucleus-accent)" size={13} /> {/if} </button> {/snippet}
<AccountSelector {accounts} {selectedDid} onSelect={selectAccount}>60 unmodified lines7 unmodified lines8910111212131415161718192018192021222323242526262728282930313233323334353636373839409 unmodified lines7 unmodified lines import { profiles } from '$lib/state.svelte';
interface Props { client: AtpClient; did: Did; size: number; did: Did | null; }
let { client, did, size }: Props = $props();
const avatarBlob = $derived(profiles.get(did)?.avatar); const avatarUrl: string | null = $derived( isBlob(avatarBlob) ? img('avatar_thumbnail', did, avatarBlob.ref.$link) : null const avatarBlob = $derived(did ? profiles.get(did)?.avatar : null); const avatarUrl = $derived( did && isBlob(avatarBlob) ? img('avatar_thumbnail', did, avatarBlob.ref.$link) : null );
const loadProfile = async (targetDid: Did) => { const loadProfile = async (client: AtpClient, did: Did) => { if (avatarBlob) return;
const profile = await client.getProfile(targetDid); const profile = await client.getProfile(did); if (profile.ok) profiles.set(did, profile.value); else console.error(`${targetDid}: failed to load pfp: ${profile.error}`); else console.error(`${did}: failed to load pfp: ${profile.error}`); };
$effect(() => { if (!client.user) return; loadProfile(did); if (!did) return; loadProfile(client, did); });
const color = $derived(generateColorForDid(did)); const color = $derived(did ? generateColorForDid(did) : 'var(--nucleus-accent)');</script>
{#if avatarUrl} <img9 unmodified lines390 unmodified linesExpand all391392393394395395396397398564 unmodified linesExpand all963964965966967968969970971972973974975976977978979980981982983119 unmodified linesExpand all390 unmodified linesExpand all if (!userDid) return;
const threeDaysAgo = (Date.now() - 3 * 24 * 60 * 60 * 1000) * 1000;
// fetch only 1 item to prompt the cursor const res = await client.listRecordsUntil(subject, 'app.bsky.feed.post', undefined, threeDaysAgo); if (!res.ok) return; const postsWithUri = res.value.records.map( (post) =>564 unmodified linesExpand all};
export const initialDone = new SvelteSet<Did>();export const fetchInitial = async (account: Account) => { const start = Date.now(); const client = clients.get(account.did)!; const profile = await client.getProfile(); if (profile.ok) profiles.set(account.did, profile.value); await Promise.allSettled([ fetchBlocks(account), fetchForInteractions(client, account.did), fetchFollows(account).then((follows) => Promise.allSettled(follows.map((follow) => fetchForInteractions(client, follow.subject)) ?? []) ) ]); initialDone.add(account.did); console.log(`initial done for ${account.did} in ${Date.now() - start}ms`);};
export const handleJetstreamEvent = async (event: JetstreamEvent) => { if (event.kind !== 'commit') return;119 unmodified linesExpand all