Cleanup getProfile
parent
ab878ba9a6
commit
2d7b89c6a1
|
@ -0,0 +1,5 @@
|
|||
import {BskyAgent} from '@atproto/api'
|
||||
|
||||
export const PUBLIC_BSKY_AGENT = new BskyAgent({
|
||||
service: 'https://api.bsky.app',
|
||||
})
|
|
@ -1,32 +1,12 @@
|
|||
import React from 'react'
|
||||
import {useQuery} from '@tanstack/react-query'
|
||||
import {BskyAgent} from '@atproto/api'
|
||||
|
||||
import {useSession} from '#/state/session'
|
||||
import {PUBLIC_BSKY_AGENT} from '#/data'
|
||||
|
||||
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],
|
||||
queryKey: ['getProfile', did],
|
||||
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})
|
||||
const res = await PUBLIC_BSKY_AGENT.getProfile({actor: did})
|
||||
return res.data
|
||||
},
|
||||
})
|
||||
|
|
|
@ -4,6 +4,7 @@ import {BskyAgent, AtpPersistSessionHandler} from '@atproto/api'
|
|||
import {networkRetry} from '#/lib/async/retry'
|
||||
import {logger} from '#/logger'
|
||||
import * as persisted from '#/state/persisted'
|
||||
import {PUBLIC_BSKY_AGENT} from '#/data'
|
||||
|
||||
export type SessionAccount = persisted.PersistedAccount
|
||||
|
||||
|
@ -43,10 +44,6 @@ export type ApiContext = {
|
|||
clearCurrentAccount: () => void
|
||||
}
|
||||
|
||||
export const PUBLIC_BSKY_AGENT = new BskyAgent({
|
||||
service: 'https://api.bsky.app',
|
||||
})
|
||||
|
||||
const StateContext = React.createContext<StateContext>({
|
||||
agent: PUBLIC_BSKY_AGENT,
|
||||
hasSession: false,
|
||||
|
|
Loading…
Reference in New Issue