From fc34bee94d2bfc67f75c3a313cffa2ef593c51d8 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Tue, 21 May 2024 21:19:21 +0800 Subject: [PATCH] feat: display collect and uncollect button --- src/renderer/src/hooks/useEntryActions.tsx | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/renderer/src/hooks/useEntryActions.tsx b/src/renderer/src/hooks/useEntryActions.tsx index db3f73a1b..74ffd1121 100644 --- a/src/renderer/src/hooks/useEntryActions.tsx +++ b/src/renderer/src/hooks/useEntryActions.tsx @@ -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",