diff --git a/src/renderer/src/components/entry-column/item-wrapper.tsx b/src/renderer/src/components/entry-column/item-wrapper.tsx index a939c157f..73d193771 100644 --- a/src/renderer/src/components/entry-column/item-wrapper.tsx +++ b/src/renderer/src/components/entry-column/item-wrapper.tsx @@ -18,7 +18,7 @@ export function EntryItemWrapper({ }) { if (!entry?.url || view === undefined) return children - const { execAction, items } = useEntryActions({ + const { items } = useEntryActions({ view, entry, }) @@ -42,7 +42,7 @@ export function EntryItemWrapper({ .map((item) => ({ type: "text", label: item.name, - click: () => execAction(item.action), + click: item.onClick, })), e, ) diff --git a/src/renderer/src/components/entry-content/share.tsx b/src/renderer/src/components/entry-content/share.tsx index c46d6b302..76553bf5d 100644 --- a/src/renderer/src/components/entry-content/share.tsx +++ b/src/renderer/src/components/entry-content/share.tsx @@ -17,7 +17,7 @@ export function EntryShare({ }) { if (!entry?.url) return null - const { execAction, items } = useEntryActions({ + const { items } = useEntryActions({ view, entry, }) @@ -34,7 +34,7 @@ export function EntryShare({ className="flex items-center text-xl no-drag-region" variant="ghost" size="sm" - onClick={() => execAction(item.action)} + onClick={item.onClick} > {item.icon ? ( diff --git a/src/renderer/src/hooks/useEntryActions.tsx b/src/renderer/src/hooks/useEntryActions.tsx index 6282b29fb..7c46497f1 100644 --- a/src/renderer/src/hooks/useEntryActions.tsx +++ b/src/renderer/src/hooks/useEntryActions.tsx @@ -5,8 +5,14 @@ import { useQuery } from "@tanstack/react-query" import { client } from "@renderer/lib/client" import { EntriesResponse } from "@renderer/lib/types" -export const useCheckEagle = () => - useQuery({ +export const useEntryActions = ({ + view, + entry, +}: { + view: number + entry: EntriesResponse[number] +}) => { + const checkEagle = useQuery({ queryKey: ["check-eagle"], queryFn: async () => { try { @@ -18,14 +24,7 @@ export const useCheckEagle = () => }, }) -export const useEntryActions = ({ - view, - entry, -}: { - view: number - entry: EntriesResponse[number] -}) => { - const checkEagle = useCheckEagle() + const { toast } = useToast() const items = [ [ @@ -34,22 +33,36 @@ export const useEntryActions = ({ className: "i-mingcute-star-line", action: "collect", disabled: !!entry.collections, + onClick: () => {}, }, { name: "Uncollect", className: "i-mingcute-star-fill", action: "uncollect", disabled: !entry.collections, + onClick: () => {}, }, { name: "Copy Link", className: "i-mingcute-link-line", action: "copyLink", + onClick: () => { + if (!entry.url) return + navigator.clipboard.writeText(entry.url) + toast({ + duration: 1000, + description: "Link copied to clipboard.", + }) + }, }, { name: "Open in Browser", className: "i-mingcute-world-2-line", action: "openInBrowser", + onClick: () => { + if (!entry.url) return + window.open(entry.url, "_blank") + }, }, { name: "Save Images to Eagle", @@ -58,37 +71,7 @@ export const useEntryActions = ({ disabled: (checkEagle.isLoading ? true : !checkEagle.data) || !entry.images?.length, - }, - { - name: "Share", - className: "i-mingcute-share-2-line", - action: "share", - }, - ], - ] - - const { toast } = useToast() - - const execAction = useCallback( - async (action: string) => { - switch (action) { - case "copyLink": - if (!entry.url) return - navigator.clipboard.writeText(entry.url) - toast({ - duration: 1000, - description: "Link copied to clipboard.", - }) - break - case "openInBrowser": - if (!entry.url) return - window.open(entry.url, "_blank") - break - case "share": - if (!entry.url) return - client.showShareMenu(entry.url) - break - case "save-to-eagle": + onClick: async () => { if (!entry.url || !entry.images?.length) return const response = await client.saveToEagle({ url: entry.url, @@ -105,14 +88,21 @@ export const useEntryActions = ({ description: "Failed to save to Eagle.", }) } - break - } - }, - [toast], - ) + }, + }, + { + name: "Share", + className: "i-mingcute-share-2-line", + action: "share", + onClick: () => { + if (!entry.url) return + client.showShareMenu(entry.url) + }, + }, + ], + ] return { - execAction, items: items[view] || items[0], } }