From bbbeec282ed8778f736aea17b6ef8a64213f013a Mon Sep 17 00:00:00 2001 From: Admin9705 <9705@duck.com> Date: Fri, 27 Jun 2025 18:00:21 -0400 Subject: [PATCH] Enhance Swaparr settings handling with dedicated refresh logic - Implemented special handling for the Swaparr enabled toggle to refresh the Apps section after saving settings. - Added a new method to refresh the Apps section, ensuring the currently selected app settings are reloaded when the Swaparr toggle changes. - Improved logging for better tracking of changes and actions related to the Swaparr settings. --- frontend/static/js/settings_forms.js | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/frontend/static/js/settings_forms.js b/frontend/static/js/settings_forms.js index 7ec94738..47717ca2 100644 --- a/frontend/static/js/settings_forms.js +++ b/frontend/static/js/settings_forms.js @@ -2376,6 +2376,22 @@ const SettingsForms = { input.addEventListener('change', () => { console.log(`[SettingsForms] Auto-save triggered for ${appType} by ${input.id || input.name || 'unnamed input'}`); + // Special handling for Swaparr enabled toggle - refresh Apps section after save + if (appType === 'swaparr' && input.id === 'swaparr_enabled') { + console.log('[SettingsForms] Swaparr enabled toggle changed, will refresh Apps section after save'); + + // Save first, then refresh Apps section + if (window.huntarrUI && window.huntarrUI.autoSaveSwaparrSettings) { + window.huntarrUI.autoSaveSwaparrSettings(true).then(() => { + console.log('[SettingsForms] Swaparr settings saved, now refreshing Apps section'); + this.refreshAppsSection(); + }).catch(error => { + console.error('[SettingsForms] Swaparr auto-save failed:', error); + }); + } + return; // Skip the general auto-save logic below since we handled it above + } + // Call the appropriate auto-save function based on app type if (appType === 'swaparr' && window.huntarrUI && window.huntarrUI.autoSaveSwaparrSettings) { window.huntarrUI.autoSaveSwaparrSettings(true).catch(error => { @@ -4464,6 +4480,25 @@ const SettingsForms = { }); } }, + + // Refresh Apps section to reflect Swaparr setting changes + refreshAppsSection: function() { + console.log('[SettingsForms] Refreshing Apps section for Swaparr toggle change'); + + // Check if Apps module is available and refresh the currently selected app + if (window.Apps && window.Apps.loadAppSettings) { + // Get the currently selected app + const appSelect = document.getElementById('appsAppSelect'); + if (appSelect && appSelect.value) { + console.log('[SettingsForms] Refreshing currently selected app:', appSelect.value); + window.Apps.loadAppSettings(appSelect.value); + } else { + console.log('[SettingsForms] No app currently selected in Apps section'); + } + } else { + console.log('[SettingsForms] Apps module not available for refresh'); + } + }, }; // Add CSS for toggle circle