Move the current agent to a global and reset RQ queries on agent change (#1946)

This commit is contained in:
Paul Frazee 2023-11-16 18:26:22 -08:00 committed by GitHub
parent 3043b32468
commit 357c752a21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 218 additions and 260 deletions

View file

@ -1,20 +1,19 @@
import {useQuery} from '@tanstack/react-query'
import {AtUri} from '@atproto/api'
import {useSession} from '#/state/session'
import {getAgent} from '#/state/session'
import {STALE} from '#/state/queries'
export const RQKEY = (uri: string) => ['resolved-uri', uri]
export function useResolveUriQuery(uri: string | undefined) {
const {agent} = useSession()
return useQuery<{uri: string; did: string}, Error>({
staleTime: STALE.INFINITY,
queryKey: RQKEY(uri || ''),
async queryFn() {
const urip = new AtUri(uri || '')
if (!urip.host.startsWith('did:')) {
const res = await agent.resolveHandle({handle: urip.host})
const res = await getAgent().resolveHandle({handle: urip.host})
urip.host = res.data.did
}
return {did: urip.host, uri: urip.toString()}