diff --git a/src/state/queries/actor-starter-packs.ts b/src/state/queries/actor-starter-packs.ts index 97cc3b5e05..29ebfd29c5 100644 --- a/src/state/queries/actor-starter-packs.ts +++ b/src/state/queries/actor-starter-packs.ts @@ -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, diff --git a/src/state/queries/my-blocked-accounts.ts b/src/state/queries/my-blocked-accounts.ts index a2e29136f5..2cbe1dea29 100644 --- a/src/state/queries/my-blocked-accounts.ts +++ b/src/state/queries/my-blocked-accounts.ts @@ -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, + InfiniteData, 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 { const queryDatas = queryClient.getQueriesData< - InfiniteData + InfiniteData >({ queryKey: [RQKEY_ROOT], }) diff --git a/src/state/queries/my-muted-accounts.ts b/src/state/queries/my-muted-accounts.ts index bf36b90296..cd1c6bc6ba 100644 --- a/src/state/queries/my-muted-accounts.ts +++ b/src/state/queries/my-muted-accounts.ts @@ -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, + InfiniteData, 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 { const queryDatas = queryClient.getQueriesData< - InfiniteData + InfiniteData >({ queryKey: [RQKEY_ROOT], }) diff --git a/src/state/queries/suggested-follows.ts b/src/state/queries/suggested-follows.ts index 7197eb2980..d33120cebb 100644 --- a/src/state/queries/suggested-follows.ts +++ b/src/state/queries/suggested-follows.ts @@ -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 + InfiniteData >({ queryKey: [suggestedFollowsQueryKeyRoot], }) @@ -135,7 +136,7 @@ function* findAllProfilesInSuggestedFollowsByActorQueryData( did: string, ) { const queryDatas = - queryClient.getQueriesData( + queryClient.getQueriesData( { queryKey: [suggestedFollowsByActorQueryKeyRoot], },