test(web): lock the sidebar highlighting behind tests
It has been reported twice and fixed twice by reading the code, which is how it came back. The decision is now a module of its own — the shell only asks it which entry is current — and twelve cases pin it down: a detail page, a query string, every spelling of the home route, and the original regression where home stayed lit everywhere. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
3 files changed
+151
-12
No files matched your search
+3
-12
@@ -1,6 +1,7 @@
|
||||
import { api } from './core/api.js';
|
||||
import { h, mount, qs } from './core/dom.js';
|
||||
import { onStatus, resetSubscriptions, startLive } from './core/live.js';
|
||||
import { activePath, highlight } from './core/nav.js';
|
||||
import { ACCESS_LABELS, button, spinner, toast } from './core/ui.js';
|
||||
|
||||
/** Shell, navigation and hash routing of the dashboard (M16-T11). */
|
||||
@@ -138,7 +139,7 @@ const currentRoute = () => {
|
||||
const raw = window.location.hash.replace(/^#\/?/, '');
|
||||
const [path] = raw.split('?');
|
||||
const segments = path.split('/').filter(Boolean);
|
||||
return { segments, path };
|
||||
return { segments, path, active: activePath(window.location.hash) };
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -148,18 +149,8 @@ const currentRoute = () => {
|
||||
* its own — otherwise it keeps pointing at the page you arrived on.
|
||||
*/
|
||||
function highlightNav(scope = document) {
|
||||
const { segments } = currentRoute();
|
||||
const active = segments[0] ?? '';
|
||||
const active = highlight(scope, window.location.hash);
|
||||
const route = ROUTES.find((entry) => entry.path === active);
|
||||
|
||||
for (const link of scope.querySelectorAll('.nav a')) {
|
||||
// Compare the route the link carries, not its href: a trailing slash or a
|
||||
// query string in the hash must not make an entry look inactive.
|
||||
const current = link.dataset.route === active;
|
||||
link.classList.toggle('active', current);
|
||||
if (current) link.setAttribute('aria-current', 'page');
|
||||
else link.removeAttribute('aria-current');
|
||||
}
|
||||
document.title = route ? `${route.label} · FWS-Bot` : 'FWS-Bot';
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user