Web login/signup and shell
This commit is contained in:
parent
487d871cfd
commit
ab878ba9a6
21 changed files with 581 additions and 374 deletions
33
src/data/useGetProfile.ts
Normal file
33
src/data/useGetProfile.ts
Normal file
|
@ -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
|
||||
},
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue