From c88c2e05562eee2d9632387e01f138559af0bca4 Mon Sep 17 00:00:00 2001 From: Gregor Eichelberger Date: Thu, 5 Dec 2024 12:14:44 +0100 Subject: [PATCH] Delete subtitle on save and process Change prepareSubtitles for WorklfowConfiguration to honor deleted subtitles. --- src/main/Save.tsx | 1 + src/main/SubtitleEditor.tsx | 2 +- src/main/SubtitleSelect.tsx | 2 +- src/main/WorkflowConfiguration.tsx | 19 +++++++------------ 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main/Save.tsx b/src/main/Save.tsx index c989e518c..156a316c5 100644 --- a/src/main/Save.tsx +++ b/src/main/Save.tsx @@ -138,6 +138,7 @@ export const SaveButton: React.FC = () => { return t("save.success-tooltip-aria"); } }; + const prepareSubtitles = () => Object.entries(subtitles).map(([id, { deleted, cues, tags }]) => ({ id, diff --git a/src/main/SubtitleEditor.tsx b/src/main/SubtitleEditor.tsx index 87ece4ed5..ac3be666c 100644 --- a/src/main/SubtitleEditor.tsx +++ b/src/main/SubtitleEditor.tsx @@ -48,7 +48,7 @@ const SubtitleEditor: React.FC = () => { try { dispatch(setSubtitle({ identifier: selectedId, - subtitles: { cues: parseSubtitle(captionTrack.subtitle), tags: captionTrack.tags }, + subtitles: { cues: parseSubtitle(captionTrack.subtitle), tags: captionTrack.tags, deleted: false }, })); } catch (error) { if (error instanceof Error) { diff --git a/src/main/SubtitleSelect.tsx b/src/main/SubtitleSelect.tsx index 1d3b29243..173919455 100644 --- a/src/main/SubtitleSelect.tsx +++ b/src/main/SubtitleSelect.tsx @@ -235,7 +235,7 @@ const SubtitleAddButton: React.FC<{ const id = values.selectedSubtitle; const relatedSubtitle = subtitlesForDropdown.find(tag => tag.id === id); const tags = relatedSubtitle ? relatedSubtitle.tags : []; - dispatch(setSubtitle({ identifier: id, subtitles: { cues: [], tags: tags } })); + dispatch(setSubtitle({ identifier: id, subtitles: { cues: [], tags: tags, delete: false } })); // Reset setIsPlusDisplay(true); diff --git a/src/main/WorkflowConfiguration.tsx b/src/main/WorkflowConfiguration.tsx index 1c8930cf4..1c4632835 100644 --- a/src/main/WorkflowConfiguration.tsx +++ b/src/main/WorkflowConfiguration.tsx @@ -100,18 +100,13 @@ export const SaveAndProcessButton: React.FC<{ text: string; }> = ({ text }) => { } }, [dispatch, workflowStatus]); - const prepareSubtitles = () => { - const subtitlesForPosting = []; - - for (const identifier in subtitles) { - subtitlesForPosting.push({ - id: identifier, - subtitle: serializeSubtitle(subtitles[identifier].cues), - tags: subtitles[identifier].tags, - }); - } - return subtitlesForPosting; - }; + const prepareSubtitles = () => + Object.entries(subtitles).map(([id, { deleted, cues, tags }]) => ({ + id, + subtitle: deleted ? "" : serializeSubtitle(cues), + tags: deleted ? [] : tags, + deleted, + })); const saveAndProcess = () => { dispatch(postVideoInformationWithWorkflow({