From a0428e05495df30198b95a17f467a97179743630 Mon Sep 17 00:00:00 2001 From: nocode Date: Wed, 23 Sep 2026 20:34:09 +0200 Subject: [PATCH] fix(web): keep the sidebar in step with the page being shown Navigating only swapped the main area, so the highlighted entry stayed on whichever page the shell was built with and nothing on screen said where you were. The highlight is now refreshed on every navigation, carries `aria-current` for screen readers and an inset marker that reads at a glance, and the browser tab takes the page name. Co-Authored-By: Claude Opus 5 (1M context) --- src/web/public/app.js | 27 ++++++++++++++++++++++++--- src/web/public/styles.css | 26 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/web/public/app.js b/src/web/public/app.js index 41b81bc..23a54c3 100644 --- a/src/web/public/app.js +++ b/src/web/public/app.js @@ -132,9 +132,26 @@ const currentRoute = () => { return { segments, path }; }; -function sidebar() { +/** + * Marks the current entry in the sidebar and retitles the tab. + * + * Navigation only swaps the main area, so the highlight has to be refreshed on + * its own — otherwise it keeps pointing at the page you arrived on. + */ +function highlightNav() { const { segments } = currentRoute(); const active = segments[0] ?? ''; + const route = ROUTES.find((entry) => entry.path === active); + + for (const link of document.querySelectorAll('.nav a')) { + link.classList.toggle('active', link.getAttribute('href') === `#/${active}`); + if (link.getAttribute('href') === `#/${active}`) link.setAttribute('aria-current', 'page'); + else link.removeAttribute('aria-current'); + } + document.title = route ? `${route.label} · FWS-Bot` : 'FWS-Bot'; +} + +function sidebar() { const visible = ROUTES.filter( (route) => state.me.accessLevel >= route.level && (!route.advanced || state.mode === 'advanced'), ); @@ -163,7 +180,7 @@ function sidebar() { group.routes.map((route) => h( 'a', - { href: `#/${route.path}`, class: route.path === active ? 'active' : '' }, + { href: `#/${route.path}` }, h('span', { class: 'nav-icon', text: route.icon }), h('span', { text: route.label }), ), @@ -226,6 +243,8 @@ function applyModeButtons(node) { async function renderView(host) { const { segments } = currentRoute(); const route = ROUTES.find((entry) => entry.path === (segments[0] ?? '')); + highlightNav(); + host.scrollIntoView?.({ block: 'start' }); if (!route) { mount(host, h('div', { class: 'notice notice-warning' }, h('p', { text: 'Page inconnue.' }))); @@ -285,7 +304,9 @@ async function boot() { state.config = config; window.addEventListener('hashchange', () => { - if (state.me?.authenticated && state.me.source !== 'setup') renderView(qs('.main')); + const main = qs('.main'); + // Without the shell in place there is nothing to swap, so rebuild the page. + if (main && state.me?.authenticated && state.me.source !== 'setup') renderView(main); else render(); }); window.addEventListener('unhandledrejection', (event) => { diff --git a/src/web/public/styles.css b/src/web/public/styles.css index f75ba4b..f24040a 100644 --- a/src/web/public/styles.css +++ b/src/web/public/styles.css @@ -192,6 +192,11 @@ pre code { background: color-mix(in srgb, var(--blue) 18%, transparent); color: var(--blue-soft); font-weight: 600; + /* Inset rather than a border: a real border would shift the label. */ + box-shadow: inset 3px 0 0 var(--blue); +} +.nav a.active .nav-icon { + opacity: 1; } .nav-icon { width: 1.15rem; @@ -685,6 +690,27 @@ pre code { padding-left: 1.2rem; } +details summary { + cursor: pointer; + font-size: 0.85rem; + font-weight: 600; + color: var(--text-muted); + padding: 0.35rem 0; + list-style-position: outside; +} +details summary:hover { + color: var(--text); +} +details[open] summary { + margin-bottom: 0.6rem; +} +details > *:not(summary) { + margin-bottom: 0.6rem; +} +details > *:last-child { + margin-bottom: 0; +} + /* --- Simple / advanced mode ---------------------------------------------- */ body[data-mode='simple'] .advanced-only {