migrate the mute, block, starter pack and suggestion queries to the appview client

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-08-03 15:16:22 +03:00
parent a8db57e00d
commit d8d4b3cf32
4 changed files with 42 additions and 39 deletions
+11 -9
View File
@@ -1,6 +1,7 @@
import {type QueryClient, useInfiniteQuery} from '@tanstack/react-query'
import {useAgent} from '#/state/session'
import {useAppviewClient} from '#/state/session'
import {app} from '#/lexicons'
export const RQKEY_ROOT = 'actor-starter-packs'
export const RQKEY_WITH_MEMBERSHIP_ROOT = 'actor-starter-packs-with-membership'
@@ -17,17 +18,17 @@ export function useActorStarterPacksQuery({
did?: string
enabled?: boolean
}) {
const agent = useAgent()
const client = useAppviewClient()
return useInfiniteQuery({
queryKey: RQKEY(did),
queryFn: async ({pageParam}: {pageParam?: string}) => {
const res = await agent.app.bsky.graph.getActorStarterPacks({
actor: did!,
return await client.call(app.bsky.graph.getActorStarterPacks, {
// the enabled flag prevents this from running until did is set
actor: did! as app.bsky.graph.getActorStarterPacks.$Params['actor'],
limit: 10,
cursor: pageParam,
})
return res.data
},
enabled: Boolean(did) && enabled,
initialPageParam: undefined,
@@ -42,17 +43,18 @@ export function useActorStarterPacksWithMembershipsQuery({
did?: string
enabled?: boolean
}) {
const agent = useAgent()
const client = useAppviewClient()
return useInfiniteQuery({
queryKey: RQKEY_WITH_MEMBERSHIP(did),
queryFn: async ({pageParam}: {pageParam?: string}) => {
const res = await agent.app.bsky.graph.getStarterPacksWithMembership({
actor: did!,
return await client.call(app.bsky.graph.getStarterPacksWithMembership, {
// the enabled flag prevents this from running until did is set
actor:
did! as app.bsky.graph.getStarterPacksWithMembership.$Params['actor'],
limit: 10,
cursor: pageParam,
})
return res.data
},
enabled: Boolean(did) && enabled,
initialPageParam: undefined,
+8 -8
View File
@@ -1,4 +1,4 @@
import {type AppBskyActorDefs, type AppBskyGraphGetBlocks} from '@atproto/api'
import {type AppBskyActorDefs} from '@atproto/api'
import {
type InfiniteData,
type QueryClient,
@@ -6,28 +6,28 @@ import {
useInfiniteQuery,
} from '@tanstack/react-query'
import {useAgent} from '#/state/session'
import {useAppviewClient} from '#/state/session'
import {app} from '#/lexicons'
const RQKEY_ROOT = 'my-blocked-accounts'
export const RQKEY = () => [RQKEY_ROOT]
type RQPageParam = string | undefined
export function useMyBlockedAccountsQuery() {
const agent = useAgent()
const client = useAppviewClient()
return useInfiniteQuery<
AppBskyGraphGetBlocks.OutputSchema,
app.bsky.graph.getBlocks.$OutputBody,
Error,
InfiniteData<AppBskyGraphGetBlocks.OutputSchema>,
InfiniteData<app.bsky.graph.getBlocks.$OutputBody>,
QueryKey,
RQPageParam
>({
queryKey: RQKEY(),
async queryFn({pageParam}: {pageParam: RQPageParam}) {
const res = await agent.app.bsky.graph.getBlocks({
return await client.call(app.bsky.graph.getBlocks, {
limit: 30,
cursor: pageParam,
})
return res.data
},
initialPageParam: undefined,
getNextPageParam: lastPage => lastPage.cursor,
@@ -39,7 +39,7 @@ export function* findAllProfilesInQueryData(
did: string,
): Generator<AppBskyActorDefs.ProfileView, void> {
const queryDatas = queryClient.getQueriesData<
InfiniteData<AppBskyGraphGetBlocks.OutputSchema>
InfiniteData<app.bsky.graph.getBlocks.$OutputBody>
>({
queryKey: [RQKEY_ROOT],
})
+8 -8
View File
@@ -1,4 +1,4 @@
import {type AppBskyActorDefs, type AppBskyGraphGetMutes} from '@atproto/api'
import {type AppBskyActorDefs} from '@atproto/api'
import {
type InfiniteData,
type QueryClient,
@@ -6,28 +6,28 @@ import {
useInfiniteQuery,
} from '@tanstack/react-query'
import {useAgent} from '#/state/session'
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 agent = useAgent()
const client = useAppviewClient()
return useInfiniteQuery<
AppBskyGraphGetMutes.OutputSchema,
app.bsky.graph.getMutes.$OutputBody,
Error,
InfiniteData<AppBskyGraphGetMutes.OutputSchema>,
InfiniteData<app.bsky.graph.getMutes.$OutputBody>,
QueryKey,
RQPageParam
>({
queryKey: RQKEY(),
async queryFn({pageParam}: {pageParam: RQPageParam}) {
const res = await agent.app.bsky.graph.getMutes({
return await client.call(app.bsky.graph.getMutes, {
limit: 30,
cursor: pageParam,
})
return res.data
},
initialPageParam: undefined,
getNextPageParam: lastPage => lastPage.cursor,
@@ -39,7 +39,7 @@ export function* findAllProfilesInQueryData(
did: string,
): Generator<AppBskyActorDefs.ProfileView, void> {
const queryDatas = queryClient.getQueriesData<
InfiniteData<AppBskyGraphGetMutes.OutputSchema>
InfiniteData<app.bsky.graph.getMutes.$OutputBody>
>({
queryKey: [RQKEY_ROOT],
})
+15 -14
View File
@@ -1,9 +1,5 @@
import {useCallback, useMemo} from 'react'
import {
type AppBskyActorDefs,
type AppBskyActorGetSuggestions,
type AppBskyGraphGetSuggestedFollowsByActor,
} from '@atproto/api'
import {type AppBskyActorDefs} from '@atproto/api'
import {
type InfiniteData,
type QueryClient,
@@ -12,7 +8,8 @@ import {
} from '@tanstack/react-query'
import {STALE} from '#/state/queries'
import {useAgent} from '#/state/session'
import {useAppviewClient} from '#/state/session'
import {app} from '#/lexicons'
import type * as bsky from '#/types/bsky'
const suggestedFollowsQueryKeyRoot = 'suggested-follows'
@@ -32,18 +29,22 @@ export function useSuggestedFollowsByActorQuery({
enabled?: boolean
staleTime?: number
}) {
const agent = useAgent()
const client = useAppviewClient()
return useQuery({
staleTime,
queryKey: suggestedFollowsByActorQueryKey(did),
queryFn: async () => {
const res = await agent.app.bsky.graph.getSuggestedFollowsByActor({
actor: did,
})
const suggestions = res.data.suggestions.filter(
const data = await client.call(
app.bsky.graph.getSuggestedFollowsByActor,
{
actor:
did as app.bsky.graph.getSuggestedFollowsByActor.$Params['actor'],
},
)
const suggestions = data.suggestions.filter(
profile => !profile.viewer?.following,
)
return {suggestions, recId: res.data.recIdStr}
return {suggestions, recId: data.recIdStr}
},
enabled,
})
@@ -112,7 +113,7 @@ function* findAllProfilesInSuggestedFollowsQueryData(
did: string,
) {
const queryDatas = queryClient.getQueriesData<
InfiniteData<AppBskyActorGetSuggestions.OutputSchema>
InfiniteData<app.bsky.actor.getSuggestions.$OutputBody>
>({
queryKey: [suggestedFollowsQueryKeyRoot],
})
@@ -135,7 +136,7 @@ function* findAllProfilesInSuggestedFollowsByActorQueryData(
did: string,
) {
const queryDatas =
queryClient.getQueriesData<AppBskyGraphGetSuggestedFollowsByActor.OutputSchema>(
queryClient.getQueriesData<app.bsky.graph.getSuggestedFollowsByActor.$OutputBody>(
{
queryKey: [suggestedFollowsByActorQueryKeyRoot],
},