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:
@@ -6,7 +6,6 @@ import Animated, {
|
|||||||
LayoutAnimationConfig,
|
LayoutAnimationConfig,
|
||||||
LinearTransition,
|
LinearTransition,
|
||||||
} from 'react-native-reanimated'
|
} from 'react-native-reanimated'
|
||||||
import {type ComAtprotoServerListAppPasswords} from '@atproto/api'
|
|
||||||
import {msg} from '@lingui/core/macro'
|
import {msg} from '@lingui/core/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
import {Trans} from '@lingui/react/macro'
|
import {Trans} from '@lingui/react/macro'
|
||||||
@@ -33,6 +32,7 @@ import {Loader} from '#/components/Loader'
|
|||||||
import * as Prompt from '#/components/Prompt'
|
import * as Prompt from '#/components/Prompt'
|
||||||
import * as Toast from '#/components/Toast'
|
import * as Toast from '#/components/Toast'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
|
import {type com} from '#/lexicons'
|
||||||
import {AddAppPasswordDialog} from './components/AddAppPasswordDialog'
|
import {AddAppPasswordDialog} from './components/AddAppPasswordDialog'
|
||||||
import * as SettingsList from './components/SettingsList'
|
import * as SettingsList from './components/SettingsList'
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ export function AppPasswordsScreen({}: Props) {
|
|||||||
function AppPasswordCard({
|
function AppPasswordCard({
|
||||||
appPassword,
|
appPassword,
|
||||||
}: {
|
}: {
|
||||||
appPassword: ComAtprotoServerListAppPasswords.AppPassword
|
appPassword: com.atproto.server.listAppPasswords.AppPassword
|
||||||
}) {
|
}) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {i18n, _} = useLingui()
|
const {i18n, _} = useLingui()
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import Animated, {
|
|||||||
SlideInRight,
|
SlideInRight,
|
||||||
SlideOutLeft,
|
SlideOutLeft,
|
||||||
} from 'react-native-reanimated'
|
} from 'react-native-reanimated'
|
||||||
import {type ComAtprotoServerCreateAppPassword} from '@atproto/api'
|
|
||||||
import {msg} from '@lingui/core/macro'
|
import {msg} from '@lingui/core/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
import {Trans} from '@lingui/react/macro'
|
import {Trans} from '@lingui/react/macro'
|
||||||
@@ -25,6 +24,7 @@ import {ChevronRight_Stroke2_Corner0_Rounded as ChevronRight} from '#/components
|
|||||||
import {SquareBehindSquare4_Stroke2_Corner0_Rounded as CopyIcon} from '#/components/icons/SquareBehindSquare4'
|
import {SquareBehindSquare4_Stroke2_Corner0_Rounded as CopyIcon} from '#/components/icons/SquareBehindSquare4'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
import {IS_WEB} from '#/env'
|
import {IS_WEB} from '#/env'
|
||||||
|
import {type com} from '#/lexicons'
|
||||||
import {CopyButton} from './CopyButton'
|
import {CopyButton} from './CopyButton'
|
||||||
|
|
||||||
export function AddAppPasswordDialog({
|
export function AddAppPasswordDialog({
|
||||||
@@ -70,7 +70,7 @@ function CreateDialogInner({passwords}: {passwords: string[]}) {
|
|||||||
error: validationError,
|
error: validationError,
|
||||||
isPending,
|
isPending,
|
||||||
} = useMutation<
|
} = useMutation<
|
||||||
ComAtprotoServerCreateAppPassword.AppPassword,
|
com.atproto.server.createAppPassword.AppPassword,
|
||||||
Error | DisplayableError
|
Error | DisplayableError
|
||||||
>({
|
>({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
|
|||||||
@@ -1,39 +1,37 @@
|
|||||||
import {type ComAtprotoServerCreateAppPassword} from '@atproto/api'
|
|
||||||
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
|
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
import {useAgent} from '../session'
|
import {com} from '#/lexicons'
|
||||||
|
import {usePdsClient} from '../session'
|
||||||
|
|
||||||
const RQKEY_ROOT = 'app-passwords'
|
const RQKEY_ROOT = 'app-passwords'
|
||||||
export const RQKEY = () => [RQKEY_ROOT]
|
export const RQKEY = () => [RQKEY_ROOT]
|
||||||
|
|
||||||
export function useAppPasswordsQuery() {
|
export function useAppPasswordsQuery() {
|
||||||
const agent = useAgent()
|
const client = usePdsClient()
|
||||||
return useQuery({
|
return useQuery({
|
||||||
staleTime: STALE.MINUTES.FIVE,
|
staleTime: STALE.MINUTES.FIVE,
|
||||||
queryKey: RQKEY(),
|
queryKey: RQKEY(),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await agent.com.atproto.server.listAppPasswords({})
|
const data = await client.call(com.atproto.server.listAppPasswords)
|
||||||
return res.data.passwords
|
return data.passwords
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useAppPasswordCreateMutation() {
|
export function useAppPasswordCreateMutation() {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const agent = useAgent()
|
const client = usePdsClient()
|
||||||
return useMutation<
|
return useMutation<
|
||||||
ComAtprotoServerCreateAppPassword.OutputSchema,
|
com.atproto.server.createAppPassword.$OutputBody,
|
||||||
Error,
|
Error,
|
||||||
{name: string; privileged: boolean}
|
{name: string; privileged: boolean}
|
||||||
>({
|
>({
|
||||||
mutationFn: async ({name, privileged}) => {
|
mutationFn: async ({name, privileged}) => {
|
||||||
return (
|
return await client.call(com.atproto.server.createAppPassword, {
|
||||||
await agent.com.atproto.server.createAppPassword({
|
|
||||||
name,
|
name,
|
||||||
privileged,
|
privileged,
|
||||||
})
|
})
|
||||||
).data
|
|
||||||
},
|
},
|
||||||
onSuccess() {
|
onSuccess() {
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
@@ -45,10 +43,10 @@ export function useAppPasswordCreateMutation() {
|
|||||||
|
|
||||||
export function useAppPasswordDeleteMutation() {
|
export function useAppPasswordDeleteMutation() {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const agent = useAgent()
|
const client = usePdsClient()
|
||||||
return useMutation<void, Error, {name: string}>({
|
return useMutation<void, Error, {name: string}>({
|
||||||
mutationFn: async ({name}) => {
|
mutationFn: async ({name}) => {
|
||||||
await agent.com.atproto.server.revokeAppPassword({
|
await client.call(com.atproto.server.revokeAppPassword, {
|
||||||
name,
|
name,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import {useCallback} from 'react'
|
import {useCallback} from 'react'
|
||||||
|
import {type HandleString} from '@atproto/syntax'
|
||||||
import {useMutation, useQueryClient} from '@tanstack/react-query'
|
import {useMutation, useQueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
import {useAgent} from '#/state/session'
|
import {useAgent, usePdsClient} from '#/state/session'
|
||||||
|
import {com} from '#/lexicons'
|
||||||
|
|
||||||
const handleQueryKeyRoot = 'handle'
|
const handleQueryKeyRoot = 'handle'
|
||||||
const fetchHandleQueryKey = (handleOrDid: string) => [
|
const fetchHandleQueryKey = (handleOrDid: string) => [
|
||||||
@@ -36,11 +38,15 @@ export function useUpdateHandleMutation(opts?: {
|
|||||||
onSuccess?: (handle: string) => void
|
onSuccess?: (handle: string) => void
|
||||||
}) {
|
}) {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const agent = useAgent()
|
const client = usePdsClient()
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async ({handle}: {handle: string}) => {
|
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) {
|
onSuccess(_data, variables) {
|
||||||
opts?.onSuccess?.(variables.handle)
|
opts?.onSuccess?.(variables.handle)
|
||||||
|
|||||||
Reference in New Issue
Block a user