From 848de1abdfda24f69e5df5429e793873ccd312ab Mon Sep 17 00:00:00 2001 From: an-lee Date: Thu, 28 Mar 2024 16:10:23 +0800 Subject: [PATCH] Fix bugs (#457) * ensure word not empty when lookup * fix null issue * fix undefined issue when video failed to add --- enjoy/src/renderer/components/stories/story-viewer.tsx | 1 + enjoy/src/renderer/components/videos/ted-talks-segment.tsx | 2 ++ enjoy/src/renderer/hooks/use-ai-command.tsx | 5 ++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/enjoy/src/renderer/components/stories/story-viewer.tsx b/enjoy/src/renderer/components/stories/story-viewer.tsx index e067d009..2cc29cf7 100644 --- a/enjoy/src/renderer/components/stories/story-viewer.tsx +++ b/enjoy/src/renderer/components/stories/story-viewer.tsx @@ -49,6 +49,7 @@ export const StoryViewer = (props: { const handleSelectionChanged = debounce(() => { const selection = document.getSelection(); + if (!selection?.anchorNode?.parentElement) return; if (!ref.current?.contains(selection.anchorNode.parentElement)) return; const word = selection diff --git a/enjoy/src/renderer/components/videos/ted-talks-segment.tsx b/enjoy/src/renderer/components/videos/ted-talks-segment.tsx index 2e018712..c84c6712 100644 --- a/enjoy/src/renderer/components/videos/ted-talks-segment.tsx +++ b/enjoy/src/renderer/components/videos/ted-talks-segment.tsx @@ -51,6 +51,8 @@ export const TedTalksSegment = () => { coverUrl: selectedTalk?.primaryImageSet[0].url, }) .then((record) => { + if (!record) return; + if (type === "video") { navigate(`/videos/${record.id}`); } else { diff --git a/enjoy/src/renderer/hooks/use-ai-command.tsx b/enjoy/src/renderer/hooks/use-ai-command.tsx index c983fbff..dc081baf 100644 --- a/enjoy/src/renderer/hooks/use-ai-command.tsx +++ b/enjoy/src/renderer/hooks/use-ai-command.tsx @@ -20,7 +20,10 @@ export const useAiCommand = () => { sourceId?: string; sourceType?: string; }) => { - const { word, context, sourceId, sourceType } = params; + const { context, sourceId, sourceType } = params; + let { word } = params; + word = word.trim(); + if (!word) return; const lookup = await webApi.lookup({ word,