import { useState, useEffect } from 'react'; import { MiniDoc, Collection, Rkey } from './types'; import { getRecord } from './microcosm'; function Pfp({ did, link }: { did: Did, link: String, }) { const CDN = 'https://cdn.bsky.app/img/avatar_thumbnail/plain'; // freeloading const url = `${CDN}/${did.val}/${link}@jpeg` return avatar; } function LilUser({ doc, children }: { doc: MiniDoc, children: any, }) { const [pfpLink, setPfpLink] = useState(null); const [displayName, setDisplayName] = useState(null); useEffect(() => { let cancel = false; (async () => { const uri = `at://${doc.did.val}/app.bsky.actor.profile/self`; const profile = await getRecord( doc.did, new Collection('app.bsky.actor.profile'), new Rkey('self'), ); const link = profile?.avatar?.ref?.$link; if (link && !cancel) setPfpLink(link); const name = profile?.displayName; if (name && !cancel) setDisplayName(name); })(); return () => cancel = true; }, [doc.did.val]); return (
{pfpLink ? : <>…}

{displayName || doc.handle.val}

{displayName && <>{doc.handle.val}
} {doc.did.val}

{children && (
{children}
)}
) } export default LilUser;