From 8a9ffb76c2280b340535225b255bc78d937e26b2 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Sat, 25 May 2024 17:48:16 +0800 Subject: [PATCH] fix: conditional hooks --- src/renderer/src/hooks/useEntryActions.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/renderer/src/hooks/useEntryActions.tsx b/src/renderer/src/hooks/useEntryActions.tsx index 5f1579b1a..2fa5b7cd4 100644 --- a/src/renderer/src/hooks/useEntryActions.tsx +++ b/src/renderer/src/hooks/useEntryActions.tsx @@ -18,10 +18,9 @@ export const useEntryActions = ({ view?: number entry?: EntriesResponse[number] }) => { - if (!entry?.url || view === undefined) return { items: [] } - const checkEagle = useQuery({ queryKey: ["check-eagle"], + enabled: !!entry?.url && !!view, queryFn: async () => { try { await ofetch("http://localhost:41595") @@ -37,7 +36,7 @@ export const useEntryActions = ({ const updateCollection = ( target: boolean, ) => { - const key = ["entry", entry.id] + const key = ["entry", entry?.id] const data = queryClient.getQueryData(key) if (data) { queryClient.setQueryData( @@ -59,7 +58,7 @@ export const useEntryActions = ({ const list = (data as InfiniteData>)?.pages?.[0]?.data if (list) { for (const item of list) { - if (item.id === entry.id) { + if (item.id === entry?.id) { item.collected = target queryClient.setQueryData(key, data) } @@ -74,7 +73,7 @@ export const useEntryActions = ({ apiFetch("/collections", { method: "POST", body: { - entryId: entry.id, + entryId: entry?.id, }, }), onSuccess: () => { @@ -91,7 +90,7 @@ export const useEntryActions = ({ apiFetch("/collections", { method: "DELETE", body: { - entryId: entry.id, + entryId: entry?.id, }, }), onSuccess: () => { @@ -106,6 +105,8 @@ export const useEntryActions = ({ const { toast } = useToast() + if (!entry?.url || view === undefined) return { items: [] } + const items = [ [ {