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.
pull/315/head
Broque Thomas 4 weeks ago
parent eb2218ec8d
commit 1446c7b63a

@ -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() {

Loading…
Cancel
Save