Post PostLikedBy and PostRepostedBy to RQ (#1913)

* Port PostRepostedBy to RQ

* Port PostLikedBy to RQ
This commit is contained in:
dan 2023-11-15 22:04:25 +00:00 committed by GitHub
parent e699df21c6
commit 839e8e8d0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 203 additions and 345 deletions

View file

@ -0,0 +1,32 @@
import {AppBskyFeedGetLikes} 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 = (resolvedUri: string) => ['post-liked-by', resolvedUri]
export function usePostLikedByQuery(resolvedUri: string | undefined) {
const {agent} = useSession()
return useInfiniteQuery<
AppBskyFeedGetLikes.OutputSchema,
Error,
InfiniteData<AppBskyFeedGetLikes.OutputSchema>,
QueryKey,
RQPageParam
>({
queryKey: RQKEY(resolvedUri || ''),
async queryFn({pageParam}: {pageParam: RQPageParam}) {
const res = await agent.getLikes({
uri: resolvedUri || '',
limit: PAGE_SIZE,
cursor: pageParam,
})
return res.data
},
initialPageParam: undefined,
getNextPageParam: lastPage => lastPage.cursor,
enabled: !!resolvedUri,
})
}

View file

@ -0,0 +1,32 @@
import {AppBskyFeedGetRepostedBy} 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 = (resolvedUri: string) => ['post-reposted-by', resolvedUri]
export function usePostRepostedByQuery(resolvedUri: string | undefined) {
const {agent} = useSession()
return useInfiniteQuery<
AppBskyFeedGetRepostedBy.OutputSchema,
Error,
InfiniteData<AppBskyFeedGetRepostedBy.OutputSchema>,
QueryKey,
RQPageParam
>({
queryKey: RQKEY(resolvedUri || ''),
async queryFn({pageParam}: {pageParam: RQPageParam}) {
const res = await agent.getRepostedBy({
uri: resolvedUri || '',
limit: PAGE_SIZE,
cursor: pageParam,
})
return res.data
},
initialPageParam: undefined,
getNextPageParam: lastPage => lastPage.cursor,
enabled: !!resolvedUri,
})
}