Sort follows and following behind gate (#11237)

This commit is contained in:
DS Boyce
2026-07-23 09:02:35 -07:00
committed by GitHub
parent 8d64ab9d4b
commit 10b027c35b
10 changed files with 114 additions and 61 deletions
+22 -3
View File
@@ -10,15 +10,33 @@ import {
} from '@tanstack/react-query'
import {useAgent} from '#/state/session'
import {useAnalytics} from '#/analytics'
const DEFAULT_SORT = 'latest'
const PAGE_SIZE = 30
type RQPageParam = string | undefined
const RQKEY_ROOT = 'profile-followers'
export const RQKEY = (did: string) => [RQKEY_ROOT, did]
export const RQKEY = (did: string, sort: 'latest' | 'top' = DEFAULT_SORT) => [
RQKEY_ROOT,
did,
sort,
]
export function useProfileFollowersQuery(did: string | undefined) {
export function useProfileFollowersQuery(
did?: string,
{
sort,
}: {
sort?: 'latest' | 'top'
} = {},
) {
const ax = useAnalytics()
const isSortEnabled = ax.features.enabled(ax.features.FollowSortEnable)
const agent = useAgent()
const sortParam = isSortEnabled ? sort || DEFAULT_SORT : undefined
return useInfiniteQuery<
AppBskyGraphGetFollowers.OutputSchema,
Error,
@@ -26,12 +44,13 @@ export function useProfileFollowersQuery(did: string | undefined) {
QueryKey,
RQPageParam
>({
queryKey: RQKEY(did || ''),
queryKey: RQKEY(did || '', sortParam),
async queryFn({pageParam}: {pageParam: RQPageParam}) {
const res = await agent.app.bsky.graph.getFollowers({
actor: did || '',
limit: PAGE_SIZE,
cursor: pageParam,
sort: sortParam,
})
return res.data
},
+17 -5
View File
@@ -8,25 +8,36 @@ import {
import {STALE} from '#/state/queries'
import {useAgent} from '#/state/session'
import {useAnalytics} from '#/analytics'
const DEFAULT_SORT = 'latest'
const PAGE_SIZE = 30
type RQPageParam = string | undefined
// TODO refactor invalidate on mutate?
const RQKEY_ROOT = 'profile-follows'
export const RQKEY = (did: string) => [RQKEY_ROOT, did]
export const RQKEY = (did: string, sort: 'latest' | 'top' = DEFAULT_SORT) => [
RQKEY_ROOT,
did,
sort,
]
export function useProfileFollowsQuery(
did: string | undefined,
{
limit,
sort,
}: {
limit?: number
} = {
limit: PAGE_SIZE,
},
sort?: 'latest' | 'top'
} = {},
) {
const ax = useAnalytics()
const isSortEnabled = ax.features.enabled(ax.features.FollowSortEnable)
const agent = useAgent()
const sortParam = isSortEnabled ? sort || DEFAULT_SORT : undefined
return useInfiniteQuery<
AppBskyGraphGetFollows.OutputSchema,
Error,
@@ -35,12 +46,13 @@ export function useProfileFollowsQuery(
RQPageParam
>({
staleTime: STALE.MINUTES.ONE,
queryKey: RQKEY(did || ''),
queryKey: RQKEY(did || '', sortParam),
async queryFn({pageParam}: {pageParam: RQPageParam}) {
const res = await agent.app.bsky.graph.getFollows({
actor: did || '',
limit: limit || PAGE_SIZE,
cursor: pageParam,
sort: sortParam,
})
return res.data
},