diff options
author | Eric Bailey <git@esb.lol> | 2023-11-09 20:35:17 -0600 |
---|---|---|
committer | Eric Bailey <git@esb.lol> | 2023-11-09 20:35:17 -0600 |
commit | ab878ba9a6afaa57805aeab988b01c5b47bc9286 (patch) | |
tree | 266f68581a5d237b0d22b4b94fb92e0e45c0993b /src/data | |
parent | 487d871cfd89948f4db9944c4bb414d268a56537 (diff) | |
download | voidsky-ab878ba9a6afaa57805aeab988b01c5b47bc9286.tar.zst |
Web login/signup and shell
Diffstat (limited to 'src/data')
-rw-r--r-- | src/data/useGetProfile.ts | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/data/useGetProfile.ts b/src/data/useGetProfile.ts new file mode 100644 index 000000000..58f24a4e8 --- /dev/null +++ b/src/data/useGetProfile.ts @@ -0,0 +1,33 @@ +import React from 'react' +import {useQuery} from '@tanstack/react-query' +import {BskyAgent} from '@atproto/api' + +import {useSession} from '#/state/session' + +export function useGetProfile({did}: {did: string}) { + const {accounts} = useSession() + const account = React.useMemo( + () => accounts.find(a => a.did === did), + [did, accounts], + ) + + return useQuery({ + enabled: !!account, + queryKey: ['getProfile', account], + queryFn: async () => { + if (!account) { + throw new Error(`useGetProfile: local account not found for ${did}`) + } + + const agent = new BskyAgent({ + // needs to be public data, so remap PDS URLs to App View for now + service: account.service.includes('bsky.social') + ? 'https://api.bsky.app' + : account.service, + }) + + const res = await agent.getProfile({actor: did}) + return res.data + }, + }) +} |