about summary refs log tree commit diff
path: root/src/state/queries/profile-feedgens.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/state/queries/profile-feedgens.ts')
-rw-r--r--src/state/queries/profile-feedgens.ts31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/state/queries/profile-feedgens.ts b/src/state/queries/profile-feedgens.ts
new file mode 100644
index 000000000..652a123d9
--- /dev/null
+++ b/src/state/queries/profile-feedgens.ts
@@ -0,0 +1,31 @@
+import {AppBskyFeedGetActorFeeds} from '@atproto/api'
+import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
+import {useSession} from '../session'
+
+const PAGE_SIZE = 30
+type RQPageParam = string | undefined
+
+export const RQKEY = (did: string) => ['profile-feedgens', did]
+
+export function useProfileFeedgensQuery(did: string) {
+  const {agent} = useSession()
+  return useInfiniteQuery<
+    AppBskyFeedGetActorFeeds.OutputSchema,
+    Error,
+    InfiniteData<AppBskyFeedGetActorFeeds.OutputSchema>,
+    QueryKey,
+    RQPageParam
+  >({
+    queryKey: RQKEY(did),
+    async queryFn({pageParam}: {pageParam: RQPageParam}) {
+      const res = await agent.app.bsky.feed.getActorFeeds({
+        actor: did,
+        limit: PAGE_SIZE,
+        cursor: pageParam,
+      })
+      return res.data
+    },
+    initialPageParam: undefined,
+    getNextPageParam: lastPage => lastPage.cursor,
+  })
+}