Skip to content

Commit

Permalink
Post PostLikedBy and PostRepostedBy to RQ (#1913)
Browse files Browse the repository at this point in the history
* Port PostRepostedBy to RQ

* Port PostLikedBy to RQ
  • Loading branch information
gaearon authored Nov 15, 2023
1 parent e699df2 commit 839e8e8
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 344 deletions.
135 changes: 0 additions & 135 deletions src/state/models/lists/likes.ts

This file was deleted.

136 changes: 0 additions & 136 deletions src/state/models/lists/reposted-by.ts

This file was deleted.

32 changes: 32 additions & 0 deletions src/state/queries/post-liked-by.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 32 additions & 0 deletions src/state/queries/post-reposted-by.ts
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 839e8e8

Please sign in to comment.