[backend/razor] Improve queue dash refresh handling

This commit is contained in:
Laura Hausmann 2024-07-22 21:45:20 +02:00
parent 5e10a4a8b2
commit fd409d52d2
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -1,5 +1,15 @@
let interval = null;
const timeout = 1000;
async function reloadTables() { async function reloadTables() {
if (document.hidden) return; if (document.hidden) {
if (interval == null) return;
clearInterval(interval);
interval = null;
return;
}
interval ??= setInterval(reloadTables, timeout);
const last = document.getElementById('last-updated').innerText; const last = document.getElementById('last-updated').innerText;
fetch(`/queue?last=${last}`).then(res => { fetch(`/queue?last=${last}`).then(res => {
@ -25,4 +35,7 @@ function docReady(fn) {
} }
} }
docReady(() => setInterval(reloadTables, 2000)); docReady(async () => {
document.addEventListener("visibilitychange", reloadTables, false);
await reloadTables();
});