Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port Profile Followers/Follows to RQ #1893

Merged
merged 8 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading