about summary refs log tree commit diff
path: root/src/state/queries/profile-lists.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/state/queries/profile-lists.ts')
-rw-r--r--src/state/queries/profile-lists.ts32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/state/queries/profile-lists.ts b/src/state/queries/profile-lists.ts
new file mode 100644
index 000000000..505d33b9f
--- /dev/null
+++ b/src/state/queries/profile-lists.ts
@@ -0,0 +1,32 @@
+import {AppBskyGraphGetLists} from '@atproto/api'
+import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
+import {getAgent} from '#/state/session'
+
+const PAGE_SIZE = 30
+type RQPageParam = string | undefined
+
+export const RQKEY = (did: string) => ['profile-lists', did]
+
+export function useProfileListsQuery(did: string, opts?: {enabled?: boolean}) {
+  const enabled = opts?.enabled !== false
+  return useInfiniteQuery<
+    AppBskyGraphGetLists.OutputSchema,
+    Error,
+    InfiniteData<AppBskyGraphGetLists.OutputSchema>,
+    QueryKey,
+    RQPageParam
+  >({
+    queryKey: RQKEY(did),
+    async queryFn({pageParam}: {pageParam: RQPageParam}) {
+      const res = await getAgent().app.bsky.graph.getLists({
+        actor: did,
+        limit: PAGE_SIZE,
+        cursor: pageParam,
+      })
+      return res.data
+    },
+    initialPageParam: undefined,
+    getNextPageParam: lastPage => lastPage.cursor,
+    enabled,
+  })
+}