From 3475a33aabeccc0da699666a4b09687e42fa06bc Mon Sep 17 00:00:00 2001 From: WithoutPants <53250216+WithoutPants@users.noreply.github.com> Date: Sun, 20 Feb 2022 11:08:21 +1100 Subject: [PATCH] Combine system preview generation options (#2328) --- .../src/components/Dialogs/GenerateDialog.tsx | 6 +- .../Settings/Tasks/LibraryTasks.tsx | 61 +++++++++++-------- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/ui/v2.5/src/components/Dialogs/GenerateDialog.tsx b/ui/v2.5/src/components/Dialogs/GenerateDialog.tsx index 1f95d54a7..70ec8c835 100644 --- a/ui/v2.5/src/components/Dialogs/GenerateDialog.tsx +++ b/ui/v2.5/src/components/Dialogs/GenerateDialog.tsx @@ -51,12 +51,14 @@ export const GenerateDialog: React.FC = ({ return; } + // combine the defaults with the system preview generation settings if (configuration?.defaults.generate) { const { generate } = configuration.defaults; setOptions(withoutTypename(generate)); setConfigRead(true); - } else if (configuration?.general) { - // backwards compatibility + } + + if (configuration?.general) { const { general } = configuration; setOptions((existing) => ({ ...existing, diff --git a/ui/v2.5/src/components/Settings/Tasks/LibraryTasks.tsx b/ui/v2.5/src/components/Settings/Tasks/LibraryTasks.tsx index 79f88b1a3..eb9045336 100644 --- a/ui/v2.5/src/components/Settings/Tasks/LibraryTasks.tsx +++ b/ui/v2.5/src/components/Settings/Tasks/LibraryTasks.tsx @@ -111,6 +111,7 @@ export const LibraryTasks: React.FC = () => { type DialogOpenState = typeof dialogOpen; const { configuration } = React.useContext(ConfigurationContext); + const [configRead, setConfigRead] = useState(false); useEffect(() => { if (!configuration?.defaults) { @@ -126,33 +127,41 @@ export const LibraryTasks: React.FC = () => { setAutoTagOptions(withoutTypename(autoTag)); } - if (configuration?.defaults.generate) { - const { generate } = configuration.defaults; - setGenerateOptions(withoutTypename(generate)); - } else if (configuration?.general) { - // backwards compatibility - const { general } = configuration; - setGenerateOptions((existing) => ({ - ...existing, - previewOptions: { - ...existing.previewOptions, - previewSegments: - general.previewSegments ?? existing.previewOptions?.previewSegments, - previewSegmentDuration: - general.previewSegmentDuration ?? - existing.previewOptions?.previewSegmentDuration, - previewExcludeStart: - general.previewExcludeStart ?? - existing.previewOptions?.previewExcludeStart, - previewExcludeEnd: - general.previewExcludeEnd ?? - existing.previewOptions?.previewExcludeEnd, - previewPreset: - general.previewPreset ?? existing.previewOptions?.previewPreset, - }, - })); + // combine the defaults with the system preview generation settings + // only do this once + if (!configRead) { + if (configuration?.defaults.generate) { + const { generate } = configuration.defaults; + setGenerateOptions(withoutTypename(generate)); + } + + if (configuration?.general) { + const { general } = configuration; + setGenerateOptions((existing) => ({ + ...existing, + previewOptions: { + ...existing.previewOptions, + previewSegments: + general.previewSegments ?? + existing.previewOptions?.previewSegments, + previewSegmentDuration: + general.previewSegmentDuration ?? + existing.previewOptions?.previewSegmentDuration, + previewExcludeStart: + general.previewExcludeStart ?? + existing.previewOptions?.previewExcludeStart, + previewExcludeEnd: + general.previewExcludeEnd ?? + existing.previewOptions?.previewExcludeEnd, + previewPreset: + general.previewPreset ?? existing.previewOptions?.previewPreset, + }, + })); + } + + setConfigRead(true); } - }, [configuration]); + }, [configuration, configRead]); function setDialogOpen(s: Partial) { setDialogOpenState((v) => {