Fix self mention, resolve handle (#1903)
* Fix self mention, resolve handle * Use queryClient * Fix type * Remove staleTime
This commit is contained in:
parent
8e4a3ad5b6
commit
ab6e3f2c5d
2 changed files with 46 additions and 8 deletions
25
src/state/queries/handle.ts
Normal file
25
src/state/queries/handle.ts
Normal 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],
|
||||
)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue