feat: display collect and uncollect button

This commit is contained in:
DIYgod 2024-05-21 21:19:21 +08:00
parent 831d402c7b
commit fc34bee94d
No known key found for this signature in database
1 changed files with 30 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import { ofetch } from "ofetch"
import { useQuery } from "@tanstack/react-query"
import { client } from "@renderer/lib/client"
import { EntriesResponse } from "@renderer/lib/types"
import { apiFetch } from "@renderer/lib/queries/api-fetch"
export const useCheckEagle = () =>
useQuery({
@ -18,6 +19,22 @@ export const useCheckEagle = () =>
},
})
export const useIsCollected = (entryId: string) =>
useQuery({
queryKey: ["is-collected", entryId],
queryFn: async () => {
const { data: collected } = await apiFetch<{
data: boolean
}>("/collections", {
query: {
entryId,
},
})
return collected
},
})
export const useEntryActions = ({
view,
entry,
@ -26,9 +43,22 @@ export const useEntryActions = ({
entry: EntriesResponse[number]
}) => {
const checkEagle = useCheckEagle()
const isCollected = useIsCollected(entry.id)
const items = [
[
{
name: "Collect",
className: "i-mingcute-star-line",
action: "collect",
disabled: isCollected.data,
},
{
name: "Uncollect",
className: "i-mingcute-star-fill",
action: "uncollect",
disabled: !isCollected.data,
},
{
name: "Copy Link",
className: "i-mingcute-link-line",