about summary refs log tree commit diff
path: root/src/state/queries
diff options
context:
space:
mode:
Diffstat (limited to 'src/state/queries')
-rw-r--r--src/state/queries/feed.ts68
-rw-r--r--src/state/queries/like.ts24
-rw-r--r--src/state/queries/suggested-feeds.ts29
3 files changed, 88 insertions, 33 deletions
diff --git a/src/state/queries/feed.ts b/src/state/queries/feed.ts
index dde37315d..4ec82c6fb 100644
--- a/src/state/queries/feed.ts
+++ b/src/state/queries/feed.ts
@@ -21,39 +21,41 @@ import {sanitizeHandle} from '#/lib/strings/handles'
 import {useSession} from '#/state/session'
 import {usePreferencesQuery} from '#/state/queries/preferences'
 
-export type FeedSourceInfo =
-  | {
-      type: 'feed'
-      uri: string
-      route: {
-        href: string
-        name: string
-        params: Record<string, string>
-      }
-      cid: string
-      avatar: string | undefined
-      displayName: string
-      description: RichText
-      creatorDid: string
-      creatorHandle: string
-      likeCount: number | undefined
-      likeUri: string | undefined
-    }
-  | {
-      type: 'list'
-      uri: string
-      route: {
-        href: string
-        name: string
-        params: Record<string, string>
-      }
-      cid: string
-      avatar: string | undefined
-      displayName: string
-      description: RichText
-      creatorDid: string
-      creatorHandle: string
-    }
+export type FeedSourceFeedInfo = {
+  type: 'feed'
+  uri: string
+  route: {
+    href: string
+    name: string
+    params: Record<string, string>
+  }
+  cid: string
+  avatar: string | undefined
+  displayName: string
+  description: RichText
+  creatorDid: string
+  creatorHandle: string
+  likeCount: number | undefined
+  likeUri: string | undefined
+}
+
+export type FeedSourceListInfo = {
+  type: 'list'
+  uri: string
+  route: {
+    href: string
+    name: string
+    params: Record<string, string>
+  }
+  cid: string
+  avatar: string | undefined
+  displayName: string
+  description: RichText
+  creatorDid: string
+  creatorHandle: string
+}
+
+export type FeedSourceInfo = FeedSourceFeedInfo | FeedSourceListInfo
 
 export const feedSourceInfoQueryKey = ({uri}: {uri: string}) => [
   'getFeedSourceInfo',
diff --git a/src/state/queries/like.ts b/src/state/queries/like.ts
new file mode 100644
index 000000000..187d8fb82
--- /dev/null
+++ b/src/state/queries/like.ts
@@ -0,0 +1,24 @@
+import {useMutation} from '@tanstack/react-query'
+
+import {useSession} from '#/state/session'
+
+export function useLikeMutation() {
+  const {agent} = useSession()
+
+  return useMutation({
+    mutationFn: async ({uri, cid}: {uri: string; cid: string}) => {
+      const res = await agent.like(uri, cid)
+      return {uri: res.uri}
+    },
+  })
+}
+
+export function useUnlikeMutation() {
+  const {agent} = useSession()
+
+  return useMutation({
+    mutationFn: async ({uri}: {uri: string}) => {
+      await agent.deleteLike(uri)
+    },
+  })
+}
diff --git a/src/state/queries/suggested-feeds.ts b/src/state/queries/suggested-feeds.ts
new file mode 100644
index 000000000..e148c97c3
--- /dev/null
+++ b/src/state/queries/suggested-feeds.ts
@@ -0,0 +1,29 @@
+import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
+import {AppBskyFeedGetSuggestedFeeds} from '@atproto/api'
+
+import {useSession} from '#/state/session'
+
+export const suggestedFeedsQueryKey = ['suggestedFeeds']
+
+export function useSuggestedFeedsQuery() {
+  const {agent} = useSession()
+
+  return useInfiniteQuery<
+    AppBskyFeedGetSuggestedFeeds.OutputSchema,
+    Error,
+    InfiniteData<AppBskyFeedGetSuggestedFeeds.OutputSchema>,
+    QueryKey,
+    string | undefined
+  >({
+    queryKey: suggestedFeedsQueryKey,
+    queryFn: async ({pageParam}) => {
+      const res = await agent.app.bsky.feed.getSuggestedFeeds({
+        limit: 10,
+        cursor: pageParam,
+      })
+      return res.data
+    },
+    initialPageParam: undefined,
+    getNextPageParam: lastPage => lastPage.cursor,
+  })
+}