From 71dfa7fb653220c21b3452fa5a6516953e0c060d Mon Sep 17 00:00:00 2001 From: Owais Jamil Date: Tue, 9 Jun 2026 15:32:53 -0500 Subject: [PATCH] feat: typeahead --- src/lib/atproto/identity.ts | 25 ++- src/lib/atproto/types.ts | 2 + src/lib/components/SetupDialog.svelte | 226 +++++++++++++++++++++++++- 3 files changed, 245 insertions(+), 8 deletions(-) diff --git a/src/lib/atproto/identity.ts b/src/lib/atproto/identity.ts index c7a1978..86ccf0d 100644 --- a/src/lib/atproto/identity.ts +++ b/src/lib/atproto/identity.ts @@ -3,9 +3,9 @@ import type { ActorIdentifier } from '@atcute/lexicons/syntax'; import type { Handle } from '@atcute/lexicons/syntax'; import type {} from '@atcute/atproto'; import type {} from '@atcute/bluesky'; -import type { AccountIdentity, DidDocument } from './types'; +import type { AccountIdentity, ActorTypeaheadResult, DidDocument } from './types'; -export type { AccountIdentity } from './types'; +export type { AccountIdentity, ActorTypeaheadResult } from './types'; export const defaultIdentity = { handle: 'desertthunder.dev', did: 'did:plc:xg2vq45muivyy3xwatcehspu' }; @@ -29,6 +29,27 @@ export async function resolveAccount(handle: string): Promise { return hydratePublicIdentity(identity.did, normalizedHandle); } +export async function searchActorsTypeahead(query: string, limit = 6): Promise { + const normalizedQuery = query.trim().replace(/^@/, ''); + + if (!normalizedQuery) { + return []; + } + + const result = await ok( + publicApi.get('app.bsky.actor.searchActorsTypeahead', { + params: { q: normalizedQuery, limit } + }) + ); + + return result.actors.map((actor) => ({ + handle: actor.handle, + did: actor.did, + displayName: actor.displayName ?? null, + avatar: actor.avatar ?? null + })); +} + export async function hydratePublicIdentity(did: string, fallbackHandle = did): Promise { if (!did.startsWith('did:')) { throw new Error('Record routes must include a DID.'); diff --git a/src/lib/atproto/types.ts b/src/lib/atproto/types.ts index 01f9da1..0f8a253 100644 --- a/src/lib/atproto/types.ts +++ b/src/lib/atproto/types.ts @@ -7,6 +7,8 @@ export type AccountIdentity = { description: string | null; }; +export type ActorTypeaheadResult = Pick; + export type DidDocument = { service?: Array<{ id?: string; type?: string; serviceEndpoint?: string | string[] | Record }>; }; diff --git a/src/lib/components/SetupDialog.svelte b/src/lib/components/SetupDialog.svelte index 5374050..197f0bd 100644 --- a/src/lib/components/SetupDialog.svelte +++ b/src/lib/components/SetupDialog.svelte @@ -1,7 +1,7 @@