Fix self mention, resolve handle (#1903)

* Fix self mention, resolve handle

* Use queryClient

* Fix type

* Remove staleTime
This commit is contained in:
Eric Bailey 2023-11-14 14:16:56 -06:00 committed by GitHub
parent 8e4a3ad5b6
commit ab6e3f2c5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 8 deletions

View file

@ -0,0 +1,25 @@
import React from 'react'
import {useQueryClient} from '@tanstack/react-query'
import {useSession} from '#/state/session'
const fetchHandleQueryKey = (handleOrDid: string) => ['handle', handleOrDid]
export function useFetchHandle() {
const {agent} = useSession()
const queryClient = useQueryClient()
return React.useCallback(
async (handleOrDid: string) => {
if (handleOrDid.startsWith('did:')) {
const res = await queryClient.fetchQuery({
queryKey: fetchHandleQueryKey(handleOrDid),
queryFn: () => agent.getProfile({actor: handleOrDid}),
})
return res.data.handle
}
return handleOrDid
},
[agent, queryClient],
)
}