-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port Profile Followers/Follows to RQ (#1893)
* Port user followers to RQ * Port user follows to RQ * Start porting FollowButton to RQ * Fix RQ key * Check pending * Fix shadow and pending states * Rm unused * Remove last usage of useFollowProfile
- Loading branch information
Showing
11 changed files
with
363 additions
and
478 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {AppBskyGraphGetFollowers} 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 = (did: string) => ['profile-followers', did] | ||
|
||
export function useProfileFollowersQuery(did: string | undefined) { | ||
const {agent} = useSession() | ||
return useInfiniteQuery< | ||
AppBskyGraphGetFollowers.OutputSchema, | ||
Error, | ||
InfiniteData<AppBskyGraphGetFollowers.OutputSchema>, | ||
QueryKey, | ||
RQPageParam | ||
>({ | ||
queryKey: RQKEY(did || ''), | ||
async queryFn({pageParam}: {pageParam: RQPageParam}) { | ||
const res = await agent.app.bsky.graph.getFollowers({ | ||
actor: did || '', | ||
limit: PAGE_SIZE, | ||
cursor: pageParam, | ||
}) | ||
return res.data | ||
}, | ||
initialPageParam: undefined, | ||
getNextPageParam: lastPage => lastPage.cursor, | ||
enabled: !!did, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {AppBskyGraphGetFollows} 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 = (did: string) => ['profile-follows', did] | ||
|
||
export function useProfileFollowsQuery(did: string | undefined) { | ||
const {agent} = useSession() | ||
return useInfiniteQuery< | ||
AppBskyGraphGetFollows.OutputSchema, | ||
Error, | ||
InfiniteData<AppBskyGraphGetFollows.OutputSchema>, | ||
QueryKey, | ||
RQPageParam | ||
>({ | ||
queryKey: RQKEY(did || ''), | ||
async queryFn({pageParam}: {pageParam: RQPageParam}) { | ||
const res = await agent.app.bsky.graph.getFollows({ | ||
actor: did || '', | ||
limit: PAGE_SIZE, | ||
cursor: pageParam, | ||
}) | ||
return res.data | ||
}, | ||
initialPageParam: undefined, | ||
getNextPageParam: lastPage => lastPage.cursor, | ||
enabled: !!did, | ||
}) | ||
} |
Oops, something went wrong.