about summary refs log tree commit diff
path: root/src/state/queries/profile-extra-info.ts
blob: 8fc32c33ebdd9e85fb1418626411371ea4fe667e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import {useQuery} from '@tanstack/react-query'

import {getAgent} from '#/state/session'
import {STALE} from '#/state/queries'

// TODO refactor invalidate on mutate?
export const RQKEY = (did: string) => ['profile-extra-info', did]

/**
 * Fetches some additional information for the profile screen which
 * is not available in the API's ProfileView
 */
export function useProfileExtraInfoQuery(did: string) {
  return useQuery({
    staleTime: STALE.MINUTES.ONE,
    queryKey: RQKEY(did),
    async queryFn() {
      const [listsRes, feedsRes] = await Promise.all([
        getAgent().app.bsky.graph.getLists({
          actor: did,
          limit: 1,
        }),
        getAgent().app.bsky.feed.getActorFeeds({
          actor: did,
          limit: 1,
        }),
      ])
      return {
        hasLists: listsRes.data.lists.length > 0,
        hasFeedgens: feedsRes.data.feeds.length > 0,
      }
    },
  })
}