about summary refs log tree commit diff
path: root/src/state/queries/like.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/state/queries/like.ts')
-rw-r--r--src/state/queries/like.ts24
1 files changed, 24 insertions, 0 deletions
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)
+    },
+  })
+}