bsky-app/src/state/queries/profile-lists.ts
Paul Frazee fcd22d4ccb
Adjust stale-caches and dont group read&unread notifs together (#2041)
* Dont group read & unread notifications together

* Remove and reduce some stale cache times

* Keep the staleTime on the post-feed

* Bring back the load-bearing staletime on profile
2023-11-29 20:27:39 -08:00

32 lines
942 B
TypeScript

import {AppBskyGraphGetLists} from '@atproto/api'
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
import {getAgent} from '#/state/session'
const PAGE_SIZE = 30
type RQPageParam = string | undefined
export const RQKEY = (did: string) => ['profile-lists', did]
export function useProfileListsQuery(did: string, opts?: {enabled?: boolean}) {
const enabled = opts?.enabled !== false
return useInfiniteQuery<
AppBskyGraphGetLists.OutputSchema,
Error,
InfiniteData<AppBskyGraphGetLists.OutputSchema>,
QueryKey,
RQPageParam
>({
queryKey: RQKEY(did),
async queryFn({pageParam}: {pageParam: RQPageParam}) {
const res = await getAgent().app.bsky.graph.getLists({
actor: did,
limit: PAGE_SIZE,
cursor: pageParam,
})
return res.data
},
initialPageParam: undefined,
getNextPageParam: lastPage => lastPage.cursor,
enabled,
})
}