Bluesky app fork with some witchin' additions 馃挮
at linkat-integration 61 lines 1.5 kB view raw
1import {type ComAtprotoServerCreateAppPassword} from '@atproto/api' 2import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query' 3 4import {STALE} from '#/state/queries' 5import {useAgent} from '../session' 6 7const RQKEY_ROOT = 'app-passwords' 8export const RQKEY = () => [RQKEY_ROOT] 9 10export function useAppPasswordsQuery() { 11 const agent = useAgent() 12 return useQuery({ 13 staleTime: STALE.MINUTES.FIVE, 14 queryKey: RQKEY(), 15 queryFn: async () => { 16 const res = await agent.com.atproto.server.listAppPasswords({}) 17 return res.data.passwords 18 }, 19 }) 20} 21 22export function useAppPasswordCreateMutation() { 23 const queryClient = useQueryClient() 24 const agent = useAgent() 25 return useMutation< 26 ComAtprotoServerCreateAppPassword.OutputSchema, 27 Error, 28 {name: string; privileged: boolean} 29 >({ 30 mutationFn: async ({name, privileged}) => { 31 return ( 32 await agent.com.atproto.server.createAppPassword({ 33 name, 34 privileged, 35 }) 36 ).data 37 }, 38 onSuccess() { 39 queryClient.invalidateQueries({ 40 queryKey: RQKEY(), 41 }) 42 }, 43 }) 44} 45 46export function useAppPasswordDeleteMutation() { 47 const queryClient = useQueryClient() 48 const agent = useAgent() 49 return useMutation<void, Error, {name: string}>({ 50 mutationFn: async ({name}) => { 51 await agent.com.atproto.server.revokeAppPassword({ 52 name, 53 }) 54 }, 55 onSuccess() { 56 queryClient.invalidateQueries({ 57 queryKey: RQKEY(), 58 }) 59 }, 60 }) 61}