diff options
Diffstat (limited to 'src/state/queries/profile-followers.ts')
-rw-r--r-- | src/state/queries/profile-followers.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/state/queries/profile-followers.ts b/src/state/queries/profile-followers.ts new file mode 100644 index 000000000..8e76a20a0 --- /dev/null +++ b/src/state/queries/profile-followers.ts @@ -0,0 +1,32 @@ +import {AppBskyGraphGetFollowers} from '@atproto/api' +import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' +import {useSession} from '../session' + +const PAGE_SIZE = 30 +type RQPageParam = string | undefined + +export const RQKEY = (did: string) => ['profile-followers', did] + +export function useProfileFollowersQuery(did: string | undefined) { + const {agent} = useSession() + return useInfiniteQuery< + AppBskyGraphGetFollowers.OutputSchema, + Error, + InfiniteData<AppBskyGraphGetFollowers.OutputSchema>, + QueryKey, + RQPageParam + >({ + queryKey: RQKEY(did || ''), + async queryFn({pageParam}: {pageParam: RQPageParam}) { + const res = await agent.app.bsky.graph.getFollowers({ + actor: did || '', + limit: PAGE_SIZE, + cursor: pageParam, + }) + return res.data + }, + initialPageParam: undefined, + getNextPageParam: lastPage => lastPage.cursor, + enabled: !!did, + }) +} |