diff --git a/webui/static/script.js b/webui/static/script.js index d79ec59d..c1c9f107 100644 --- a/webui/static/script.js +++ b/webui/static/script.js @@ -66465,6 +66465,12 @@ function _autoImportStopPolling() { } async function _autoImportToggle(enabled) { + // Optimistically update toggle state so it doesn't flicker + const toggle = document.getElementById('auto-import-enabled'); + if (toggle) toggle.checked = enabled; + const statusText = document.getElementById('auto-import-status-text'); + if (statusText) statusText.textContent = enabled ? 'Starting...' : 'Stopping...'; + try { const res = await fetch('/api/auto-import/toggle', { method: 'POST', headers: { 'Content-Type': 'application/json' }, @@ -66474,8 +66480,14 @@ async function _autoImportToggle(enabled) { if (data.success) { showToast(enabled ? 'Auto-import enabled' : 'Auto-import disabled', 'success'); _autoImportLoadStatus(); + } else { + // Revert on failure + if (toggle) toggle.checked = !enabled; } - } catch (e) { showToast('Error: ' + e.message, 'error'); } + } catch (e) { + showToast('Error: ' + e.message, 'error'); + if (toggle) toggle.checked = !enabled; + } } async function _autoImportLoadStatus() {