migrate the app password and update handle mutations to the pds client
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,39 +1,37 @@
|
||||
import {type ComAtprotoServerCreateAppPassword} from '@atproto/api'
|
||||
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
|
||||
|
||||
import {STALE} from '#/state/queries'
|
||||
import {useAgent} from '../session'
|
||||
import {com} from '#/lexicons'
|
||||
import {usePdsClient} from '../session'
|
||||
|
||||
const RQKEY_ROOT = 'app-passwords'
|
||||
export const RQKEY = () => [RQKEY_ROOT]
|
||||
|
||||
export function useAppPasswordsQuery() {
|
||||
const agent = useAgent()
|
||||
const client = usePdsClient()
|
||||
return useQuery({
|
||||
staleTime: STALE.MINUTES.FIVE,
|
||||
queryKey: RQKEY(),
|
||||
queryFn: async () => {
|
||||
const res = await agent.com.atproto.server.listAppPasswords({})
|
||||
return res.data.passwords
|
||||
const data = await client.call(com.atproto.server.listAppPasswords)
|
||||
return data.passwords
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useAppPasswordCreateMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const agent = useAgent()
|
||||
const client = usePdsClient()
|
||||
return useMutation<
|
||||
ComAtprotoServerCreateAppPassword.OutputSchema,
|
||||
com.atproto.server.createAppPassword.$OutputBody,
|
||||
Error,
|
||||
{name: string; privileged: boolean}
|
||||
>({
|
||||
mutationFn: async ({name, privileged}) => {
|
||||
return (
|
||||
await agent.com.atproto.server.createAppPassword({
|
||||
name,
|
||||
privileged,
|
||||
})
|
||||
).data
|
||||
return await client.call(com.atproto.server.createAppPassword, {
|
||||
name,
|
||||
privileged,
|
||||
})
|
||||
},
|
||||
onSuccess() {
|
||||
queryClient.invalidateQueries({
|
||||
@@ -45,10 +43,10 @@ export function useAppPasswordCreateMutation() {
|
||||
|
||||
export function useAppPasswordDeleteMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const agent = useAgent()
|
||||
const client = usePdsClient()
|
||||
return useMutation<void, Error, {name: string}>({
|
||||
mutationFn: async ({name}) => {
|
||||
await agent.com.atproto.server.revokeAppPassword({
|
||||
await client.call(com.atproto.server.revokeAppPassword, {
|
||||
name,
|
||||
})
|
||||
},
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import {useCallback} from 'react'
|
||||
import {type HandleString} from '@atproto/syntax'
|
||||
import {useMutation, useQueryClient} from '@tanstack/react-query'
|
||||
|
||||
import {STALE} from '#/state/queries'
|
||||
import {useAgent} from '#/state/session'
|
||||
import {useAgent, usePdsClient} from '#/state/session'
|
||||
import {com} from '#/lexicons'
|
||||
|
||||
const handleQueryKeyRoot = 'handle'
|
||||
const fetchHandleQueryKey = (handleOrDid: string) => [
|
||||
@@ -36,11 +38,15 @@ export function useUpdateHandleMutation(opts?: {
|
||||
onSuccess?: (handle: string) => void
|
||||
}) {
|
||||
const queryClient = useQueryClient()
|
||||
const agent = useAgent()
|
||||
const client = usePdsClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({handle}: {handle: string}) => {
|
||||
await agent.updateHandle({handle})
|
||||
// `agent.updateHandle` was a pure alias for this method
|
||||
await client.call(com.atproto.identity.updateHandle, {
|
||||
// callers validate the handle before submitting
|
||||
handle: handle as HandleString,
|
||||
})
|
||||
},
|
||||
onSuccess(_data, variables) {
|
||||
opts?.onSuccess?.(variables.handle)
|
||||
|
||||
Reference in New Issue
Block a user