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.
This commit is contained in:
parent
eb2218ec8d
commit
1446c7b63a
1 changed files with 13 additions and 1 deletions
|
|
@ -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…
Reference in a new issue