finish editing
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
import {AppBskyGraphGetActorStarterPacks} from '@atproto/api'
|
||||
import {InfiniteData, QueryKey, useInfiniteQuery} from '@tanstack/react-query'
|
||||
import {
|
||||
InfiniteData,
|
||||
QueryClient,
|
||||
QueryKey,
|
||||
useInfiniteQuery,
|
||||
} from '@tanstack/react-query'
|
||||
|
||||
import {STALE} from 'state/queries/index'
|
||||
import {useAgent} from 'state/session'
|
||||
|
||||
const RQKEY_ROOT = 'actor-starter-packs'
|
||||
const RQKEY = (did?: string) => [RQKEY_ROOT, did]
|
||||
|
||||
export function useActorStarterPacksQuery({did}: {did?: string}) {
|
||||
const agent = useAgent()
|
||||
@@ -16,7 +21,7 @@ export function useActorStarterPacksQuery({did}: {did?: string}) {
|
||||
QueryKey,
|
||||
string | undefined
|
||||
>({
|
||||
queryKey: [RQKEY_ROOT, did],
|
||||
queryKey: RQKEY(did),
|
||||
queryFn: async ({pageParam}: {pageParam?: string}) => {
|
||||
const res = await agent.app.bsky.graph.getActorStarterPacks({
|
||||
actor: did!,
|
||||
@@ -28,6 +33,15 @@ export function useActorStarterPacksQuery({did}: {did?: string}) {
|
||||
enabled: Boolean(did),
|
||||
initialPageParam: undefined,
|
||||
getNextPageParam: lastPage => lastPage.cursor,
|
||||
staleTime: STALE.MINUTES.ONE,
|
||||
})
|
||||
}
|
||||
|
||||
export async function invalidateActorStarterPacksQuery({
|
||||
queryClient,
|
||||
did,
|
||||
}: {
|
||||
queryClient: QueryClient
|
||||
did: string
|
||||
}) {
|
||||
await queryClient.invalidateQueries({queryKey: RQKEY(did)})
|
||||
}
|
||||
|
||||
@@ -40,6 +40,16 @@ export function useListMembersQuery(uri?: string, limit: number = PAGE_SIZE) {
|
||||
})
|
||||
}
|
||||
|
||||
export async function invalidateListMembersQuery({
|
||||
queryClient,
|
||||
uri,
|
||||
}: {
|
||||
queryClient: QueryClient
|
||||
uri: string
|
||||
}) {
|
||||
await queryClient.invalidateQueries({queryKey: RQKEY(uri)})
|
||||
}
|
||||
|
||||
export function* findAllProfilesInQueryData(
|
||||
queryClient: QueryClient,
|
||||
did: string,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import {StarterPackView} from '@atproto/api/dist/client/types/app/bsky/graph/defs'
|
||||
import {useMutation, useQuery} from '@tanstack/react-query'
|
||||
import {QueryClient, useMutation, useQuery} from '@tanstack/react-query'
|
||||
|
||||
import {STALE} from 'state/queries/index'
|
||||
import {useAgent, useSession} from 'state/session'
|
||||
|
||||
const RQKEY_ROOT = 'starter-pack'
|
||||
const RQKEY = (did?: string, rkey?: string) => [RQKEY_ROOT, did, rkey]
|
||||
|
||||
export function useStarterPackQuery({
|
||||
did,
|
||||
@@ -17,7 +17,7 @@ export function useStarterPackQuery({
|
||||
const uri = `at://${did}/app.bsky.graph.starterpack/${rkey}`
|
||||
|
||||
return useQuery<StarterPackView>({
|
||||
queryKey: [RQKEY_ROOT, did, rkey],
|
||||
queryKey: RQKEY(did, rkey),
|
||||
queryFn: async () => {
|
||||
const res = await agent.app.bsky.graph.getStarterPack({
|
||||
starterPack: uri,
|
||||
@@ -25,7 +25,6 @@ export function useStarterPackQuery({
|
||||
return res.data.starterPack
|
||||
},
|
||||
enabled: Boolean(did) && Boolean(rkey),
|
||||
staleTime: STALE.MINUTES.FIVE,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -40,13 +39,32 @@ export function useDeleteStarterPackMutation({
|
||||
const {currentAccount} = useSession()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (rkey: string) => {
|
||||
mutationFn: async (rkey: string, listRkey?: string) => {
|
||||
await agent.app.bsky.graph.starterpack.delete({
|
||||
repo: currentAccount!.did,
|
||||
rkey,
|
||||
})
|
||||
|
||||
if (listRkey) {
|
||||
await agent.app.bsky.graph.list.delete({
|
||||
repo: currentAccount!.did,
|
||||
rkey: listRkey,
|
||||
})
|
||||
}
|
||||
},
|
||||
onError,
|
||||
onSuccess,
|
||||
})
|
||||
}
|
||||
|
||||
export async function invalidateStarterPack({
|
||||
queryClient,
|
||||
did,
|
||||
rkey,
|
||||
}: {
|
||||
queryClient: QueryClient
|
||||
did: string
|
||||
rkey: string
|
||||
}) {
|
||||
await queryClient.invalidateQueries({queryKey: RQKEY(did, rkey)})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user