[backend/razor] Improve queue dash refresh handling
This commit is contained in:
parent
5e10a4a8b2
commit
fd409d52d2
1 changed files with 15 additions and 2 deletions
|
@ -1,5 +1,15 @@
|
|||
let interval = null;
|
||||
const timeout = 1000;
|
||||
|
||||
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;
|
||||
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();
|
||||
});
|
Loading…
Add table
Reference in a new issue