diff options
author | dan <dan.abramov@gmail.com> | 2023-11-15 22:04:25 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-15 14:04:25 -0800 |
commit | 839e8e8d0ade22ce47678229a98fe602c31601c3 (patch) | |
tree | ecac6c465d8d016182a709da6347d321968a1c95 /src/state/queries/post-liked-by.ts | |
parent | e699df21c66f2f55d34af4d2a14c03d02274b43e (diff) | |
download | voidsky-839e8e8d0ade22ce47678229a98fe602c31601c3.tar.zst |
Post PostLikedBy and PostRepostedBy to RQ (#1913)
* Port PostRepostedBy to RQ * Port PostLikedBy to RQ
Diffstat (limited to 'src/state/queries/post-liked-by.ts')
-rw-r--r-- | src/state/queries/post-liked-by.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/state/queries/post-liked-by.ts b/src/state/queries/post-liked-by.ts new file mode 100644 index 000000000..78ce9f60a --- /dev/null +++ b/src/state/queries/post-liked-by.ts @@ -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, + }) +} |