add query

This commit is contained in:
Hailey
2024-06-06 15:36:57 -07:00
parent e3cec97385
commit e9c0bfa8e5
4 changed files with 110 additions and 28 deletions
+33
View File
@@ -0,0 +1,33 @@
import {AppBskyGraphGetActorStarterPacks} from '@atproto/api'
import {InfiniteData, QueryKey, useInfiniteQuery} from '@tanstack/react-query'
import {STALE} from 'state/queries/index'
import {useAgent} from 'state/session'
const RQKEY_ROOT = 'actor-starter-packs'
export function useActorStarterPacksQuery({did}: {did?: string}) {
const agent = useAgent()
return useInfiniteQuery<
AppBskyGraphGetActorStarterPacks.OutputSchema,
Error,
InfiniteData<AppBskyGraphGetActorStarterPacks.OutputSchema>,
QueryKey,
string | undefined
>({
queryKey: [RQKEY_ROOT, 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,
staleTime: STALE.MINUTES.ONE,
})
}