Move the current agent to a global and reset RQ queries on agent change (#1946)
This commit is contained in:
@@ -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()}
|
||||
|
||||
Reference in New Issue
Block a user