feat(web): refresh the pages as the events arrive

One `EventSource` for the whole dashboard, held in a single slot: a view that
re-renders itself would otherwise register a second listener each time and
double the work on every event.

A refresh landing under someone's fingers is worse than data a few seconds
old, so it waits while a dialog is open or a field has focus, a burst of
writes collapses into one reload, and a background tab closes its stream.
The Discord page stays off the tick because listing members calls the
Discord API. When the stream cannot be established a timer takes over.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
nocodeandClaude Opus 5 committed 2026-09-23 20:39:59 +02:00
1 parent df89cc5893
commit 5481e79dc4
8 files changed
+255

No files matched your search

+33
View File
@@ -1,5 +1,6 @@
import { api } from './core/api.js';
import { h, mount, qs } from './core/dom.js';
import { onStatus, resetSubscriptions, startLive } from './core/live.js';
import { ACCESS_LABELS, button, spinner, toast } from './core/ui.js';
/** Shell, navigation and hash routing of the dashboard (M16-T11). */
@@ -151,6 +152,34 @@ function highlightNav() {
document.title = route ? `${route.label} · FWS-Bot` : 'FWS-Bot';
}
const LIVE_LABELS = {
live: 'À jour en direct',
connecting: 'Connexion…',
reconnecting: 'Reconnexion…',
polling: 'Rafraîchissement périodique',
paused: 'En pause (onglet en arrière-plan)',
idle: 'Hors ligne',
};
let stopWatchingStatus = null;
/** Small footer badge: says whether the page is following the bot live. */
function liveIndicator() {
const dot = h('span', { class: 'live-dot' });
const label = h('span', { text: LIVE_LABELS.idle });
const node = h('div', { class: 'live', title: 'État de la mise à jour automatique' }, dot, label);
stopWatchingStatus?.();
stopWatchingStatus = onStatus(({ status, lastEventAt }) => {
node.dataset.status = status;
label.textContent = LIVE_LABELS[status] ?? status;
if (lastEventAt) {
node.title = `Dernière mise à jour à ${lastEventAt.toLocaleTimeString('fr-FR')}`;
}
});
return node;
}
function sidebar() {
const visible = ROUTES.filter(
(route) => state.me.accessLevel >= route.level && (!route.advanced || state.mode === 'advanced'),
@@ -196,6 +225,7 @@ function sidebar() {
button('Simple', () => setMode('simple'), {}),
button('Avancé', () => setMode('advanced'), {}),
),
liveIndicator(),
h(
'div',
{ class: 'viewer' },
@@ -243,6 +273,7 @@ function applyModeButtons(node) {
async function renderView(host) {
const { segments } = currentRoute();
const route = ROUTES.find((entry) => entry.path === (segments[0] ?? ''));
resetSubscriptions();
highlightNav();
host.scrollIntoView?.({ block: 'start' });
@@ -303,6 +334,8 @@ async function boot() {
state.me = me;
state.config = config;
startLive();
window.addEventListener('hashchange', () => {
const main = qs('.main');
// Without the shell in place there is nothing to swap, so rebuild the page.