From d8ad33ff77b3feffda7dc4fbbe760194d7765f34 Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Thu, 2 Oct 2025 11:45:39 -0500 Subject: [PATCH] Fix bug where m3u hash settings wouldn't save properly. --- frontend/src/pages/Settings.jsx | 40 +++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/frontend/src/pages/Settings.jsx b/frontend/src/pages/Settings.jsx index ff39adb9..b2da545d 100644 --- a/frontend/src/pages/Settings.jsx +++ b/frontend/src/pages/Settings.jsx @@ -56,6 +56,9 @@ const SettingsPage = () => { // Add a new state to track the dialog type const [rehashDialogType, setRehashDialogType] = useState(null); // 'save' or 'rehash' + + // Store pending changed settings when showing the dialog + const [pendingChangedSettings, setPendingChangedSettings] = useState(null); // UI / local storage settings const [tableSize, setTableSize] = useLocalStorage('table-size', 'default'); @@ -201,6 +204,8 @@ const SettingsPage = () => { // If M3U hash key changed, show warning (unless suppressed) if (m3uHashKeyChanged && !isWarningSuppressed('rehash-streams')) { + // Store the changed settings before showing dialog + setPendingChangedSettings(changedSettings); setRehashDialogType('save'); // Set dialog type to save setRehashConfirmOpen(true); return; @@ -305,23 +310,28 @@ const SettingsPage = () => { const executeSettingsSaveAndRehash = async () => { setRehashConfirmOpen(false); - // First save the settings - const values = form.getValues(); - const changedSettings = {}; + // Use the stored pending values that were captured before the dialog was shown + const changedSettings = pendingChangedSettings || {}; - for (const settingKey in values) { - if (String(values[settingKey]) !== String(settings[settingKey].value)) { - changedSettings[settingKey] = `${values[settingKey]}`; + // Update each changed setting in the backend (create if missing) + for (const updatedKey in changedSettings) { + const existing = settings[updatedKey]; + if (existing && existing.id) { + await API.updateSetting({ + ...existing, + value: changedSettings[updatedKey], + }); + } else { + await API.createSetting({ + key: updatedKey, + name: updatedKey.replace(/-/g, ' '), + value: changedSettings[updatedKey], + }); } } - - // Update each changed setting in the backend - for (const updatedKey in changedSettings) { - await API.updateSetting({ - ...settings[updatedKey], - value: changedSettings[updatedKey], - }); - } + + // Clear the pending values + setPendingChangedSettings(null); }; const executeRehashStreamsOnly = async () => { @@ -876,6 +886,8 @@ const SettingsPage = () => { onClose={() => { setRehashConfirmOpen(false); setRehashDialogType(null); + // Clear pending values when dialog is cancelled + setPendingChangedSettings(null); }} onConfirm={handleRehashConfirm} title={