[Session] Add useAgent hook and replace (#3706)

* Hook it up

* Memoize getAgent method

* Use one shared reference

---------

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
This commit is contained in:
Eric Bailey 2024-04-25 16:29:05 -05:00 committed by GitHub
parent d8c8e1e854
commit 45d354cd0c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
53 changed files with 231 additions and 114 deletions

View file

@ -2,12 +2,13 @@ import {ComAtprotoServerCreateAppPassword} from '@atproto/api'
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
import {STALE} from '#/state/queries'
import {getAgent} from '../session'
import {useAgent} from '../session'
const RQKEY_ROOT = 'app-passwords'
export const RQKEY = () => [RQKEY_ROOT]
export function useAppPasswordsQuery() {
const {getAgent} = useAgent()
return useQuery({
staleTime: STALE.MINUTES.FIVE,
queryKey: RQKEY(),
@ -20,6 +21,7 @@ export function useAppPasswordsQuery() {
export function useAppPasswordCreateMutation() {
const queryClient = useQueryClient()
const {getAgent} = useAgent()
return useMutation<
ComAtprotoServerCreateAppPassword.OutputSchema,
Error,
@ -42,6 +44,7 @@ export function useAppPasswordCreateMutation() {
export function useAppPasswordDeleteMutation() {
const queryClient = useQueryClient()
const {getAgent} = useAgent()
return useMutation<void, Error, {name: string}>({
mutationFn: async ({name}) => {
await getAgent().com.atproto.server.revokeAppPassword({