46b63accb8
* Reset * Associate shadows with the cache * Use colocated helpers * Fix types * Reorder for clarity * More types * Copy paste logic for profile * Hook up profile query * Hook up suggested follows * Hook up other profile things * Fix shape * Pass setShadow into the effect deps * Include reply posts in the shadow cache search --------- Co-authored-by: Paul Frazee <pfrazee@gmail.com>
61 lines
1.5 KiB
TypeScript
61 lines
1.5 KiB
TypeScript
import {AppBskyActorDefs, AppBskyGraphGetFollowers} from '@atproto/api'
|
|
import {
|
|
useInfiniteQuery,
|
|
InfiniteData,
|
|
QueryClient,
|
|
QueryKey,
|
|
} from '@tanstack/react-query'
|
|
|
|
import {getAgent} from '#/state/session'
|
|
|
|
const PAGE_SIZE = 30
|
|
type RQPageParam = string | undefined
|
|
|
|
export const RQKEY = (did: string) => ['profile-followers', did]
|
|
|
|
export function useProfileFollowersQuery(did: string | undefined) {
|
|
return useInfiniteQuery<
|
|
AppBskyGraphGetFollowers.OutputSchema,
|
|
Error,
|
|
InfiniteData<AppBskyGraphGetFollowers.OutputSchema>,
|
|
QueryKey,
|
|
RQPageParam
|
|
>({
|
|
queryKey: RQKEY(did || ''),
|
|
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
|
const res = await getAgent().app.bsky.graph.getFollowers({
|
|
actor: did || '',
|
|
limit: PAGE_SIZE,
|
|
cursor: pageParam,
|
|
})
|
|
return res.data
|
|
},
|
|
initialPageParam: undefined,
|
|
getNextPageParam: lastPage => lastPage.cursor,
|
|
enabled: !!did,
|
|
})
|
|
}
|
|
|
|
export function* findAllProfilesInQueryData(
|
|
queryClient: QueryClient,
|
|
did: string,
|
|
): Generator<AppBskyActorDefs.ProfileView, void> {
|
|
const queryDatas = queryClient.getQueriesData<
|
|
InfiniteData<AppBskyGraphGetFollowers.OutputSchema>
|
|
>({
|
|
queryKey: ['profile-followers'],
|
|
})
|
|
for (const [_queryKey, queryData] of queryDatas) {
|
|
if (!queryData?.pages) {
|
|
continue
|
|
}
|
|
for (const page of queryData?.pages) {
|
|
for (const follower of page.followers) {
|
|
if (follower.did === did) {
|
|
yield follower
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|