import {AppBskyGraphGetActorStarterPacks} from '@atproto/api' import { InfiniteData, QueryClient, QueryKey, useInfiniteQuery, } from '@tanstack/react-query' import {useAgent} from 'state/session' const RQKEY_ROOT = 'actor-starter-packs' export const RQKEY = (did?: string) => [RQKEY_ROOT, did] export function useActorStarterPacksQuery({did}: {did?: string}) { const agent = useAgent() return useInfiniteQuery< AppBskyGraphGetActorStarterPacks.OutputSchema, Error, InfiniteData, QueryKey, string | undefined >({ queryKey: RQKEY(did), queryFn: async ({pageParam}: {pageParam?: string}) => { const res = await agent.app.bsky.graph.getActorStarterPacks({ actor: did!, limit: 10, cursor: pageParam, }) return res.data }, enabled: Boolean(did), initialPageParam: undefined, getNextPageParam: lastPage => lastPage.cursor, }) } export async function invalidateActorStarterPacksQuery({ queryClient, did, }: { queryClient: QueryClient did: string }) { await queryClient.invalidateQueries({queryKey: RQKEY(did)}) }