diff options
author | Eric Bailey <git@esb.lol> | 2023-11-14 14:16:56 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-14 14:16:56 -0600 |
commit | ab6e3f2c5d9c658ca5cae76d035f951f056b8d6f (patch) | |
tree | c4bced09d665855014931c6e35490171c4804074 /src/state/queries | |
parent | 8e4a3ad5b6c5abac57559f5711261b9868eb0cd1 (diff) | |
download | voidsky-ab6e3f2c5d9c658ca5cae76d035f951f056b8d6f.tar.zst |
Fix self mention, resolve handle (#1903)
* Fix self mention, resolve handle * Use queryClient * Fix type * Remove staleTime
Diffstat (limited to 'src/state/queries')
-rw-r--r-- | src/state/queries/handle.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/state/queries/handle.ts b/src/state/queries/handle.ts new file mode 100644 index 000000000..97e9b2107 --- /dev/null +++ b/src/state/queries/handle.ts @@ -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], + ) +} |