diff --git a/src/app/(features)/dictionary/DictionaryClient.tsx b/src/app/(features)/dictionary/DictionaryClient.tsx index 910a9f9..b213d59 100644 --- a/src/app/(features)/dictionary/DictionaryClient.tsx +++ b/src/app/(features)/dictionary/DictionaryClient.tsx @@ -90,11 +90,11 @@ export function DictionaryClient({ initialFolders }: DictionaryClientProps) { const folderSelect = document.getElementById("folder-select") as HTMLSelectElement; const folderId = folderSelect?.value ? Number(folderSelect.value) : folders[0]?.id; - if (!searchResult) return; + if (!searchResult?.entries?.length) return; - const definition = searchResult.entries.reduce((p, e) => { - return { ...p, definition: p.definition + ' | ' + e.definition }; - }).definition; + const definition = searchResult.entries + .map((e) => e.definition) + .join(" | "); try { await actionCreatePair({ @@ -102,7 +102,7 @@ export function DictionaryClient({ initialFolders }: DictionaryClientProps) { text2: definition, language1: queryLang, language2: definitionLang, - ipa1: searchResult.entries[0].ipa, + ipa1: searchResult.entries[0]?.ipa, folderId: folderId, }); diff --git a/src/app/(features)/srt-player/utils/subtitleParser.ts b/src/app/(features)/srt-player/utils/subtitleParser.ts index b49eba6..17246df 100644 --- a/src/app/(features)/srt-player/utils/subtitleParser.ts +++ b/src/app/(features)/srt-player/utils/subtitleParser.ts @@ -62,13 +62,12 @@ export function getNearestIndex( ): number | null { for (let i = 0; i < subtitles.length; i++) { const subtitle = subtitles[i]; - const isBefore = currentTime - subtitle.start >= 0; - const isAfter = currentTime - subtitle.end >= 0; + const isWithin = currentTime >= subtitle.start && currentTime <= subtitle.end; - if (!isBefore || !isAfter) return i - 1; - if (isBefore && !isAfter) return i; + if (isWithin) return i; + if (currentTime < subtitle.start) return i > 0 ? i - 1 : null; } - return null; + return subtitles.length > 0 ? subtitles.length - 1 : null; } export function getCurrentSubtitle( diff --git a/src/app/(features)/text-speaker/SaveList.tsx b/src/app/(features)/text-speaker/SaveList.tsx index 98674f5..a031bb5 100644 --- a/src/app/(features)/text-speaker/SaveList.tsx +++ b/src/app/(features)/text-speaker/SaveList.tsx @@ -60,11 +60,12 @@ export function SaveList({ show = false, handleUse }: SaveListProps) { const [data, setData] = useState(getFromLocalStorage()); const handleDel = (item: z.infer) => { const current_data = getFromLocalStorage(); + if (!current_data) return; - current_data.splice( - current_data.findIndex((v) => v.text === item.text), - 1, - ); + const index = current_data.findIndex((v) => v.text === item.text); + if (index === -1) return; + + current_data.splice(index, 1); setIntoLocalStorage(current_data); refresh(); }; @@ -78,33 +79,25 @@ export function SaveList({ show = false, handleUse }: SaveListProps) { refresh(); } }; - if (show) + if (show && data) return (
-
- - +

{t("saved")}

+
-