ui: Fix errors after migration

This commit is contained in:
nemunaire 2022-10-24 10:36:38 +02:00
commit d791e74a2a
10 changed files with 110 additions and 96 deletions

View file

@ -30,22 +30,24 @@ function createIssuesStore() {
}
}
async function refreshFunc(cb=null, interval=null) {
if (refresh_interval_issues)
clearInterval(refresh_interval_issues);
if (interval === null) {
interval = Math.floor(Math.random() * 24000) + 32000;
}
if (stop_refresh) {
return;
}
refresh_interval_issues = setInterval(refreshFunc, interval);
updateFunc(await fetch('issues.json', {headers: {'Accept': 'application/json'}}), cb);
}
return {
subscribe,
refresh: async (cb=null, interval=null) => {
if (refresh_interval_issues)
clearInterval(refresh_interval_issues);
if (interval === null) {
interval = Math.floor(Math.random() * 24000) + 32000;
}
if (stop_refresh) {
return;
}
refresh_interval_issues = setInterval(refresh_issues, interval);
updateFunc(await fetch('issues.json', {headers: {'Accept': 'application/json'}}), cb);
},
refresh: refreshFunc,
update: updateFunc,
};

View file

@ -40,22 +40,24 @@ function createMyStore() {
}
}
async function refreshFunc(cb=null, interval=null) {
if (refresh_interval_my)
clearInterval(refresh_interval_my);
if (interval === null) {
interval = Math.floor(Math.random() * 24000) + 24000;
}
if (stop_refresh) {
return;
}
refresh_interval_my = setInterval(refreshFunc, interval);
updateFunc(await fetch('my.json', {headers: {'Accept': 'application/json'}}), cb);
}
return {
subscribe,
refresh: async (cb=null, interval=null) => {
if (refresh_interval_my)
clearInterval(refresh_interval_my);
if (interval === null) {
interval = Math.floor(Math.random() * 24000) + 24000;
}
if (stop_refresh) {
return;
}
refresh_interval_my = setInterval(refresh_my, interval);
updateFunc(await fetch('my.json', {headers: {'Accept': 'application/json'}}), cb);
},
refresh: refreshFunc,
update: updateFunc,
};

View file

@ -1,6 +1,7 @@
import { readable, writable } from 'svelte/store';
import { stop_refresh } from './common';
import { my } from './my';
let refresh_interval_settings = null;
@ -40,41 +41,43 @@ function createSettingsStore() {
}
}
async function refreshFunc(cb=null, interval=null) {
if (refresh_interval_settings)
clearInterval(refresh_interval_settings);
if (interval === null) {
interval = Math.floor(Math.random() * 24000) + 32000;
}
if (stop_refresh) {
return;
}
refresh_interval_settings = setInterval(refreshFunc, interval);
if (!cb) {
// Before we start, update settings more frequently.
cb = function(stgs) {
const srv_cur = new Date(Date.now() + (stgs.currentTime - stgs.recvTime));
if (settings.start > srv_cur) {
const startIn = settings.start - srv_cur;
if (startIn > 15000) {
setTimeout(refreshFunc, Math.floor(Math.random() * 10000) + 2400)
} else if (startIn > 1500) {
setTimeout(refreshFunc, startIn - 1000 - Math.floor(Math.random() * 500))
} else {
// On scheduled start time, refresh my.json file
setTimeout(my.refresh, startIn + Math.floor(Math.random() * 200))
}
}
};
}
updateFunc(await fetch('settings.json', {headers: {'Accept': 'application/json'}}), cb);
};
return {
subscribe,
refresh: async (cb=null, interval=null) => {
if (refresh_interval_settings)
clearInterval(refresh_interval_settings);
if (interval === null) {
interval = Math.floor(Math.random() * 24000) + 32000;
}
if (stop_refresh) {
return;
}
refresh_interval_settings = setInterval(refresh_settings, interval);
if (!cb) {
// Before we start, update settings more frequently.
cb = function(stgs) {
const srv_cur = new Date(Date.now() + (stgs.currentTime - stgs.recvTime));
if (settings.start > srv_cur) {
const startIn = settings.start - srv_cur;
if (startIn > 15000) {
setTimeout(refresh_settings, Math.floor(Math.random() * 10000) + 2400)
} else if (startIn > 1500) {
setTimeout(refresh_settings, startIn - 1000 - Math.floor(Math.random() * 500))
} else {
// On scheduled start time, refresh my.json file
setTimeout(refresh_my, startIn + Math.floor(Math.random() * 200))
}
}
};
}
updateFunc(await fetch('settings.json', {headers: {'Accept': 'application/json'}}), cb);
},
refresh: refreshFunc,
update: updateFunc,
}

View file

@ -28,22 +28,24 @@ function createTeamsStore() {
}
}
async function refreshFunc(cb=null, interval=null) {
if (refresh_interval_teams)
clearInterval(refresh_interval_teams);
if (interval === null) {
interval = Math.floor(Math.random() * 24000) + 32000;
}
if (stop_refresh) {
return;
}
refresh_interval_teams = setInterval(refreshFunc, interval);
updateFunc(await fetch('teams.json', {headers: {'Accept': 'application/json'}}), cb);
}
return {
subscribe,
refresh: async (cb=null, interval=null) => {
if (refresh_interval_teams)
clearInterval(refresh_interval_teams);
if (interval === null) {
interval = Math.floor(Math.random() * 24000) + 32000;
}
if (stop_refresh) {
return;
}
refresh_interval_teams = setInterval(refresh_teams, interval);
updateFunc(await fetch('teams.json', {headers: {'Accept': 'application/json'}}), cb);
},
refresh: refreshFunc,
update: updateFunc,
};

View file

@ -50,22 +50,24 @@ function createThemesStore() {
}
}
async function refreshFunc(cb=null, interval=null) {
if (refresh_interval_themes)
clearInterval(refresh_interval_themes);
if (interval === null) {
interval = Math.floor(Math.random() * 24000) + 32000;
}
if (stop_refresh) {
return;
}
refresh_interval_themes = setInterval(refreshFunc, interval);
await updateFunc(await fetch('themes.json', {headers: {'Accept': 'application/json'}}), cb);
}
return {
subscribe,
refresh: async (cb=null, interval=null) => {
if (refresh_interval_themes)
clearInterval(refresh_interval_themes);
if (interval === null) {
interval = Math.floor(Math.random() * 24000) + 32000;
}
if (stop_refresh) {
return;
}
refresh_interval_themes = setInterval(refresh_themes, interval);
await updateFunc(await fetch('themes.json', {headers: {'Accept': 'application/json'}}), cb);
},
refresh: refreshFunc,
update: updateFunc,
};