import { shallowRef, ref } from 'vue' import type { AppBskyActorDefs } from '@atcute/bluesky' export function usePagedProfiles() { const items = shallowRef([]) const cursor = ref(null) const loading = ref(false) const error = ref(null) async function fetchPage( fetcher: (cursor?: string | null) => Promise<{ items: T[]; cursor?: string | null }>, reset = false, ) { if (loading.value) return loading.value = true error.value = null if (reset) { items.value = [] cursor.value = null } try { const res = await fetcher(cursor.value || undefined) items.value.push(...res.items) cursor.value = res.cursor ?? null } catch (e) { error.value = e instanceof Error ? e.message : String(e) } finally { loading.value = false } } return { items, cursor, loading, error, fetchPage } }