wip bsky client for the web & android bbell.vt3e.cat
at main 33 lines 901 B view raw
1import { shallowRef, ref } from 'vue' 2import type { AppBskyActorDefs } from '@atcute/bluesky' 3 4export function usePagedProfiles<T extends AppBskyActorDefs.ProfileView>() { 5 const items = shallowRef<T[]>([]) 6 const cursor = ref<string | null>(null) 7 const loading = ref(false) 8 const error = ref<string | null>(null) 9 10 async function fetchPage( 11 fetcher: (cursor?: string | null) => Promise<{ items: T[]; cursor?: string | null }>, 12 reset = false, 13 ) { 14 if (loading.value) return 15 loading.value = true 16 error.value = null 17 if (reset) { 18 items.value = [] 19 cursor.value = null 20 } 21 try { 22 const res = await fetcher(cursor.value || undefined) 23 items.value.push(...res.items) 24 cursor.value = res.cursor ?? null 25 } catch (e) { 26 error.value = e instanceof Error ? e.message : String(e) 27 } finally { 28 loading.value = false 29 } 30 } 31 32 return { items, cursor, loading, error, fetchPage } 33}