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