Move the current agent to a global and reset RQ queries on agent change (#1946)

This commit is contained in:
Paul Frazee
2023-11-16 18:26:22 -08:00
committed by GitHub
parent 3043b32468
commit 357c752a21
40 changed files with 218 additions and 260 deletions
+4 -7
View File
@@ -1,25 +1,23 @@
import {ComAtprotoServerCreateAppPassword} from '@atproto/api'
import {useQuery, useQueryClient, useMutation} from '@tanstack/react-query'
import {useSession} from '#/state/session'
import {STALE} from '#/state/queries'
import {getAgent} from '../session'
export const RQKEY = () => ['app-passwords']
export function useAppPasswordsQuery() {
const {agent} = useSession()
return useQuery({
staleTime: STALE.MINUTES.ONE,
queryKey: RQKEY(),
queryFn: async () => {
const res = await agent.com.atproto.server.listAppPasswords({})
const res = await getAgent().com.atproto.server.listAppPasswords({})
return res.data.passwords
},
})
}
export function useAppPasswordCreateMutation() {
const {agent} = useSession()
const queryClient = useQueryClient()
return useMutation<
ComAtprotoServerCreateAppPassword.OutputSchema,
@@ -28,7 +26,7 @@ export function useAppPasswordCreateMutation() {
>({
mutationFn: async ({name}) => {
return (
await agent.com.atproto.server.createAppPassword({
await getAgent().com.atproto.server.createAppPassword({
name,
})
).data
@@ -42,11 +40,10 @@ export function useAppPasswordCreateMutation() {
}
export function useAppPasswordDeleteMutation() {
const {agent} = useSession()
const queryClient = useQueryClient()
return useMutation<void, Error, {name: string}>({
mutationFn: async ({name}) => {
await agent.com.atproto.server.revokeAppPassword({
await getAgent().com.atproto.server.revokeAppPassword({
name,
})
},