0912119c77
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
import {type AppBskyActorDefs} from '@atproto/api'
|
|
import {
|
|
type InfiniteData,
|
|
type QueryClient,
|
|
type QueryKey,
|
|
useInfiniteQuery,
|
|
} from '@tanstack/react-query'
|
|
|
|
import {useAppviewClient} from '#/state/session'
|
|
import {app} from '#/lexicons'
|
|
|
|
const RQKEY_ROOT = 'my-muted-accounts'
|
|
export const RQKEY = () => [RQKEY_ROOT]
|
|
type RQPageParam = string | undefined
|
|
|
|
export function useMyMutedAccountsQuery() {
|
|
const client = useAppviewClient()
|
|
return useInfiniteQuery<
|
|
app.bsky.graph.getMutes.$OutputBody,
|
|
Error,
|
|
InfiniteData<app.bsky.graph.getMutes.$OutputBody>,
|
|
QueryKey,
|
|
RQPageParam
|
|
>({
|
|
queryKey: RQKEY(),
|
|
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
|
return await client.call(app.bsky.graph.getMutes, {
|
|
limit: 30,
|
|
cursor: pageParam,
|
|
})
|
|
},
|
|
initialPageParam: undefined,
|
|
getNextPageParam: lastPage => lastPage.cursor,
|
|
})
|
|
}
|
|
|
|
export function* findAllProfilesInQueryData(
|
|
queryClient: QueryClient,
|
|
did: string,
|
|
): Generator<AppBskyActorDefs.ProfileView, void> {
|
|
const queryDatas = queryClient.getQueriesData<
|
|
InfiniteData<app.bsky.graph.getMutes.$OutputBody>
|
|
>({
|
|
queryKey: [RQKEY_ROOT],
|
|
})
|
|
for (const [_queryKey, queryData] of queryDatas) {
|
|
if (!queryData?.pages) {
|
|
continue
|
|
}
|
|
for (const page of queryData?.pages) {
|
|
for (const mute of page.mutes) {
|
|
if (mute.did === did) {
|
|
yield mute
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|