-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix self mention, resolve handle (#1903)
* Fix self mention, resolve handle * Use queryClient * Fix type * Remove staleTime
- Loading branch information
1 parent
8e4a3ad
commit ab6e3f2
Showing
2 changed files
with
46 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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], | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters