diff --git a/frontend/src/pages/Settings.jsx b/frontend/src/pages/Settings.jsx index 23928367..a2693459 100644 --- a/frontend/src/pages/Settings.jsx +++ b/frontend/src/pages/Settings.jsx @@ -192,6 +192,7 @@ const SettingsPage = () => { useState([]); const [proxySettingsSaved, setProxySettingsSaved] = useState(false); + const [generalSettingsSaved, setGeneralSettingsSaved] = useState(false); const [rehashingStreams, setRehashingStreams] = useState(false); const [rehashSuccess, setRehashSuccess] = useState(false); const [rehashConfirmOpen, setRehashConfirmOpen] = useState(false); @@ -323,7 +324,7 @@ const SettingsPage = () => { switch (key) { case 'm3u-hash-key': // Split comma-separated string, filter out empty strings - val = value.value ? value.value.split(',').filter(v => v) : []; + val = value.value ? value.value.split(',').filter((v) => v) : []; break; case 'dvr-pre-offset-minutes': case 'dvr-post-offset-minutes': @@ -401,7 +402,17 @@ const SettingsPage = () => { loadComskipConfig(); }, []); + // Clear success states when switching accordion panels + useEffect(() => { + setGeneralSettingsSaved(false); + setProxySettingsSaved(false); + setNetworkAccessSaved(false); + setRehashSuccess(false); + }, [accordianValue]); + const onSubmit = async () => { + setGeneralSettingsSaved(false); + const values = form.getValues(); const changedSettings = {}; let m3uHashKeyChanged = false; @@ -409,7 +420,7 @@ const SettingsPage = () => { for (const settingKey in values) { // Only compare against existing value if the setting exists const existing = settings[settingKey]; - + // Convert array values (like m3u-hash-key) to comma-separated strings let stringValue; if (Array.isArray(values[settingKey])) { @@ -417,12 +428,12 @@ const SettingsPage = () => { } else { stringValue = `${values[settingKey]}`; } - + // Skip empty values to avoid validation errors if (!stringValue) { continue; } - + if (!existing) { // Create new setting on save changedSettings[settingKey] = stringValue; @@ -447,20 +458,36 @@ const SettingsPage = () => { } // 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], - }); + try { + for (const updatedKey in changedSettings) { + const existing = settings[updatedKey]; + if (existing && existing.id) { + const result = await API.updateSetting({ + ...existing, + value: changedSettings[updatedKey], + }); + // API functions return undefined on error + if (!result) { + throw new Error('Failed to update setting'); + } + } else { + const result = await API.createSetting({ + key: updatedKey, + name: updatedKey.replace(/-/g, ' '), + value: changedSettings[updatedKey], + }); + // API functions return undefined on error + if (!result) { + throw new Error('Failed to create setting'); + } + } } + + setGeneralSettingsSaved(true); + } catch (error) { + // Error notifications are already shown by API functions + // Just don't show the success message + console.error('Error saving settings:', error); } }; @@ -490,12 +517,19 @@ const SettingsPage = () => { const onProxySettingsSubmit = async () => { setProxySettingsSaved(false); - await API.updateSetting({ - ...settings['proxy-settings'], - value: JSON.stringify(proxySettingsForm.getValues()), - }); - - setProxySettingsSaved(true); + try { + const result = await API.updateSetting({ + ...settings['proxy-settings'], + value: JSON.stringify(proxySettingsForm.getValues()), + }); + // API functions return undefined on error + if (result) { + setProxySettingsSaved(true); + } + } catch (error) { + // Error notifications are already shown by API functions + console.error('Error saving proxy settings:', error); + } }; const onComskipUpload = async () => { @@ -583,29 +617,46 @@ const SettingsPage = () => { const executeSettingsSaveAndRehash = async () => { setRehashConfirmOpen(false); + setGeneralSettingsSaved(false); // Use the stored pending values that were captured before the dialog was shown const changedSettings = pendingChangedSettings || {}; // 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], - }); + try { + for (const updatedKey in changedSettings) { + const existing = settings[updatedKey]; + if (existing && existing.id) { + const result = await API.updateSetting({ + ...existing, + value: changedSettings[updatedKey], + }); + // API functions return undefined on error + if (!result) { + throw new Error('Failed to update setting'); + } + } else { + const result = await API.createSetting({ + key: updatedKey, + name: updatedKey.replace(/-/g, ' '), + value: changedSettings[updatedKey], + }); + // API functions return undefined on error + if (!result) { + throw new Error('Failed to create setting'); + } + } } - } - // Clear the pending values - setPendingChangedSettings(null); + // Clear the pending values + setPendingChangedSettings(null); + setGeneralSettingsSaved(true); + } catch (error) { + // Error notifications are already shown by API functions + // Just don't show the success message + console.error('Error saving settings:', error); + setPendingChangedSettings(null); + } }; const executeRehashStreamsOnly = async () => { @@ -726,6 +777,13 @@ const SettingsPage = () => {
+ {generalSettingsSaved && ( + + )} { Stream Settings + {generalSettingsSaved && ( + + )}