feat: unify live dashboard snapshot (#131)
CI / lint (pull_request) Successful in 9s
CI / build-frontend (pull_request) Successful in 4s

This commit is contained in:
timmy committed 2026-08-06 19:29:21 +00:00
1 parent e2a4b60143
commit 30f92d18a2
10 files changed
+421 -128

No files matched your search

+14 -15
View File
@@ -324,8 +324,8 @@ textarea { resize: vertical; min-height: 120px; }
function setClock() { qs('#clock').textContent = fmt(new Date()); }
setClock(); setInterval(setClock, 1000);
async function fetchContextSnapshot() {
const res = await fetch('api/v1/context', { headers: { Accept: 'application/json' } });
async function fetchLiveSnapshot() {
const res = await fetch('api/v1/live', { headers: { Accept: 'application/json' } });
if (!res.ok) throw new Error('HTTP ' + res.status);
return res.json();
}
@@ -552,14 +552,13 @@ textarea { resize: vertical; min-height: 120px; }
qs('#gitea-events-status').textContent = message;
}
async function loadEventStream() {
setEventStreamStatus('Updating…');
try {
const res = await fetch('api/v1/events', { headers: { Accept: 'application/json' } });
if (!res.ok) throw new Error('HTTP ' + res.status);
paintEventStream(await res.json());
function renderLiveSnapshot(snapshot) {
if (snapshot.context) renderContextSnapshot(snapshot.context);
else handleContextError(new Error('Context section unavailable'));
if (snapshot.events) {
paintEventStream(snapshot.events);
setEventStreamStatus('Updated ' + fmt(new Date()));
} catch (e) {
} else {
setEventStreamStatus('Update failed · showing last activity');
}
}
@@ -664,9 +663,12 @@ textarea { resize: vertical; min-height: 120px; }
});
const contextPoller = createContextPoller({
fetchContext: fetchContextSnapshot,
onSnapshot: renderContextSnapshot,
onError: handleContextError,
fetchContext: fetchLiveSnapshot,
onSnapshot: renderLiveSnapshot,
onError: error => {
handleContextError(error);
setEventStreamStatus('Update failed · showing last activity');
},
isHidden: () => document.hidden,
intervalMs: 8000,
});
@@ -689,11 +691,8 @@ textarea { resize: vertical; min-height: 120px; }
});
});
contextPoller.start();
loadEventStream();
setInterval(() => { if (!document.hidden) loadEventStream(); }, 5000);
document.addEventListener('visibilitychange', () => {
contextPoller.setVisible(!document.hidden);
if (!document.hidden) loadEventStream();
});
/* Widgets */