Retro Bulletin Board Systems on atproto. Web app and TUI. lazy mirror of alyraffauf/atbbs atbbs.xyz
forums python tui atproto bbs
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 50 lines 1.4 kB view raw
1/** Debounced BBS resolution — resolves a handle to a BBS name if one exists. */ 2 3import { useEffect, useState } from "react"; 4import { resolveIdentity, getRecord, getAvatar } from "../lib/atproto"; 5import { SITE } from "../lib/lexicon"; 6import { bbsUrl } from "../lib/routes"; 7import type { Suggestion } from "../components/dashboard/DialBBS"; 8 9const DEBOUNCE_MS = 300; 10 11export function useResolvedBBS(query: string): Suggestion | null { 12 const [result, setResult] = useState<Suggestion | null>(null); 13 14 useEffect(() => { 15 const trimmed = query.trim(); 16 if (!trimmed || !trimmed.includes(".")) { 17 setResult(null); 18 return; 19 } 20 21 let cancelled = false; 22 const timeout = setTimeout(async () => { 23 try { 24 const identity = await resolveIdentity(trimmed); 25 const [siteRecord, avatar] = await Promise.all([ 26 getRecord(identity.did, SITE, "self"), 27 getAvatar(identity.did), 28 ]); 29 const siteValue = siteRecord.value as { name?: string }; 30 if (!cancelled) { 31 setResult({ 32 to: bbsUrl(identity.handle), 33 name: siteValue.name ?? identity.handle, 34 handle: identity.handle, 35 avatar, 36 }); 37 } 38 } catch { 39 if (!cancelled) setResult(null); 40 } 41 }, DEBOUNCE_MS); 42 43 return () => { 44 cancelled = true; 45 clearTimeout(timeout); 46 }; 47 }, [query]); 48 49 return result; 50}