about summary refs log tree commit diff
path: root/src/state/queries/like.ts
blob: 75e93951a5e51eefd6947c3cb276a87214256472 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import {useMutation} from '@tanstack/react-query'

import {useAgent} from '#/state/session'

export function useLikeMutation() {
  const {getAgent} = useAgent()
  return useMutation({
    mutationFn: async ({uri, cid}: {uri: string; cid: string}) => {
      const res = await getAgent().like(uri, cid)
      return {uri: res.uri}
    },
  })
}

export function useUnlikeMutation() {
  const {getAgent} = useAgent()
  return useMutation({
    mutationFn: async ({uri}: {uri: string}) => {
      await getAgent().deleteLike(uri)
    },
  })
}