Fix spinner appearing every 5 secds
This commit is contained in:
@@ -74,8 +74,12 @@
|
|||||||
return timestamp < Date.now() / 1000;
|
return timestamp < Date.now() / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchAll() {
|
let isFetching = false;
|
||||||
|
async function fetchAll(silent = false) {
|
||||||
|
if (isFetching) return;
|
||||||
|
isFetching = true;
|
||||||
try {
|
try {
|
||||||
|
if (!silent) status = "loading";
|
||||||
const [sys, ota, upcoming] = await Promise.all([
|
const [sys, ota, upcoming] = await Promise.all([
|
||||||
getSystemInfo(),
|
getSystemInfo(),
|
||||||
getOTAStatus(),
|
getOTAStatus(),
|
||||||
@@ -91,6 +95,8 @@
|
|||||||
status = "error";
|
status = "error";
|
||||||
errorMsg = e.message || "Connection failed";
|
errorMsg = e.message || "Connection failed";
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
isFetching = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,8 +113,8 @@
|
|||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
fetchAll();
|
fetchAll();
|
||||||
// Poll for status updates every 5 seconds
|
// Poll for status updates every 5 seconds (silently to avoid flashing)
|
||||||
const interval = setInterval(fetchAll, 5000);
|
const interval = setInterval(() => fetchAll(true), 5000);
|
||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -8,16 +8,18 @@
|
|||||||
// Subscribe to the store
|
// Subscribe to the store
|
||||||
const unsubscribe = pendingRequests.subscribe(count => {
|
const unsubscribe = pendingRequests.subscribe(count => {
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
// Only show the spinner if the request takes longer than 300ms
|
// Only show the spinner if the request takes longer than 1000ms
|
||||||
if (!timer) {
|
if (!timer) {
|
||||||
timer = setTimeout(() => {
|
timer = setTimeout(() => {
|
||||||
showSpinner = true;
|
showSpinner = true;
|
||||||
}, 300);
|
}, 1000);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Instantly hide the spinner when all requests finish
|
// Instantly hide the spinner when all requests finish
|
||||||
|
if (timer) {
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
timer = null;
|
timer = null;
|
||||||
|
}
|
||||||
showSpinner = false;
|
showSpinner = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user