Post PostLikedBy and PostRepostedBy to RQ (#1913)
* Port PostRepostedBy to RQ * Port PostLikedBy to RQ
This commit is contained in:
parent
e699df21c6
commit
839e8e8d0a
6 changed files with 203 additions and 345 deletions
32
src/state/queries/post-liked-by.ts
Normal file
32
src/state/queries/post-liked-by.ts
Normal 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,
|
||||
})
|
||||
}
|
32
src/state/queries/post-reposted-by.ts
Normal file
32
src/state/queries/post-reposted-by.ts
Normal 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,
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue