From 1446c7b63a6749ced7340e402be534cfdc5e7388 Mon Sep 17 00:00:00 2001 From: Broque Thomas <26755000+Nezreka@users.noreply.github.com> Date: Fri, 17 Apr 2026 16:33:05 -0700 Subject: [PATCH] Fix auto-import toggle visual flicker Toggle state was set by browser click, then immediately overwritten by the status reload callback. Now optimistically sets the toggle and status text before the API call, reverting only on failure. --- webui/static/script.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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() {