* 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
33 lines
970 B
TypeScript
33 lines
970 B
TypeScript
import {AppBskyFeedGetLikes} from '@atproto/api'
|
|
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
|
|
|
import {getAgent} from '#/state/session'
|
|
|
|
const PAGE_SIZE = 30
|
|
type RQPageParam = string | undefined
|
|
|
|
// TODO refactor invalidate on mutate?
|
|
export const RQKEY = (resolvedUri: string) => ['post-liked-by', resolvedUri]
|
|
|
|
export function usePostLikedByQuery(resolvedUri: string | undefined) {
|
|
return useInfiniteQuery<
|
|
AppBskyFeedGetLikes.OutputSchema,
|
|
Error,
|
|
InfiniteData<AppBskyFeedGetLikes.OutputSchema>,
|
|
QueryKey,
|
|
RQPageParam
|
|
>({
|
|
queryKey: RQKEY(resolvedUri || ''),
|
|
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
|
const res = await getAgent().getLikes({
|
|
uri: resolvedUri || '',
|
|
limit: PAGE_SIZE,
|
|
cursor: pageParam,
|
|
})
|
|
return res.data
|
|
},
|
|
initialPageParam: undefined,
|
|
getNextPageParam: lastPage => lastPage.cursor,
|
|
enabled: !!resolvedUri,
|
|
})
|
|
}
|