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 {