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) <noreply@anthropic.com>
This commit is contained in:
nocodeandClaude Opus 5 committed 2026-09-23 20:34:09 +02:00
1 parent 20ff701430
commit a0428e0549
2 files changed
+50 -3

No files matched your search

+24 -3
View File
@@ -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) => {
+26
View File
@@ -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 {