diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-11-16 18:26:22 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-16 18:26:22 -0800 |
commit | 357c752a213dbcf77e5333fa180cfef20a33842d (patch) | |
tree | e955e57cc1252b5fe759cde29185d62bb71bc339 /src/state/queries/handle.ts | |
parent | 3043b324681f1702ca53831701fb5cecd14c0efb (diff) | |
download | voidsky-357c752a213dbcf77e5333fa180cfef20a33842d.tar.zst |
Move the current agent to a global and reset RQ queries on agent change (#1946)
Diffstat (limited to 'src/state/queries/handle.ts')
-rw-r--r-- | src/state/queries/handle.ts | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/state/queries/handle.ts b/src/state/queries/handle.ts index d73e068ec..d7c411699 100644 --- a/src/state/queries/handle.ts +++ b/src/state/queries/handle.ts @@ -1,14 +1,13 @@ import React from 'react' import {useQueryClient, useMutation} from '@tanstack/react-query' -import {useSession} from '#/state/session' +import {getAgent} from '#/state/session' import {STALE} from '#/state/queries' const fetchHandleQueryKey = (handleOrDid: string) => ['handle', handleOrDid] const fetchDidQueryKey = (handleOrDid: string) => ['did', handleOrDid] export function useFetchHandle() { - const {agent} = useSession() const queryClient = useQueryClient() return React.useCallback( @@ -17,23 +16,22 @@ export function useFetchHandle() { const res = await queryClient.fetchQuery({ staleTime: STALE.MINUTES.FIVE, queryKey: fetchHandleQueryKey(handleOrDid), - queryFn: () => agent.getProfile({actor: handleOrDid}), + queryFn: () => getAgent().getProfile({actor: handleOrDid}), }) return res.data.handle } return handleOrDid }, - [agent, queryClient], + [queryClient], ) } export function useUpdateHandleMutation() { - const {agent} = useSession() const queryClient = useQueryClient() return useMutation({ mutationFn: async ({handle}: {handle: string}) => { - await agent.updateHandle({handle}) + await getAgent().updateHandle({handle}) }, onSuccess(_data, variables) { queryClient.invalidateQueries({ @@ -44,7 +42,6 @@ export function useUpdateHandleMutation() { } export function useFetchDid() { - const {agent} = useSession() const queryClient = useQueryClient() return React.useCallback( @@ -55,13 +52,13 @@ export function useFetchDid() { queryFn: async () => { let identifier = handleOrDid if (!identifier.startsWith('did:')) { - const res = await agent.resolveHandle({handle: identifier}) + const res = await getAgent().resolveHandle({handle: identifier}) identifier = res.data.did } return identifier }, }) }, - [agent, queryClient], + [queryClient], ) } |