Skip to content

Commit

Permalink
Port Profile Followers/Follows to RQ (#1893)
Browse files Browse the repository at this point in the history
* 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
gaearon authored Nov 15, 2023
1 parent d1cb74f commit e699df2
Show file tree
Hide file tree
Showing 11 changed files with 363 additions and 478 deletions.
55 changes: 0 additions & 55 deletions src/lib/hooks/useFollowProfile.ts

This file was deleted.

121 changes: 0 additions & 121 deletions src/state/models/lists/user-followers.ts

This file was deleted.

121 changes: 0 additions & 121 deletions src/state/models/lists/user-follows.ts

This file was deleted.

32 changes: 32 additions & 0 deletions src/state/queries/profile-followers.ts
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,
})
}
32 changes: 32 additions & 0 deletions src/state/queries/profile-follows.ts
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,
})
}
Loading

0 comments on commit e699df2

Please sign in to comment.