Favourite pages that follow the user, and a narrow icon-only sidebar

A star beside each page in the sidebar pins it under "Favourites" at the top of
the menu; the list is saved with the user (users.favorites, migration 0020), so
it follows them to any browser, is offered first in the search box, and can be
changed from there too. A button at the foot of the sidebar, or the [ key,
narrows it to a strip of icons, where a group's pages open in a small menu
beside its icon and the alert and maintenance counts stay visible; the choice
is kept per browser and applies only on wide screens. Menu text on a coloured
(environment) sidebar is full strength for contrast, and menu badges sit in
line on a phone.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-15 22:38:48 +02:00
1 parent 57fd4f8c52
commit 65263a64e3
17 files changed
+2736 -86

No files matched your search

+37 -8
View File
@@ -1,5 +1,5 @@
import { useEffect, useMemo, useRef, useState, type KeyboardEvent as ReactKeyboardEvent } from "react";
import { useNavigate } from "react-router-dom";
import { useLocation, useNavigate } from "react-router-dom";
import { IconSearch } from "@tabler/icons-react";
import {
api,
@@ -12,7 +12,8 @@ import {
type SearchResponse,
type SecretType,
} from "../api/client";
import { isGroup, visibleNav } from "../layout/nav";
import { isCurrent, isGroup, visibleNav, type NavLeaf } from "../layout/nav";
import { toggleFavorite, useFavorites } from "../utils/favorites";
import { SHOW_SHORTCUTS_EVENT, shortcutHintFor } from "../layout/shortcuts";
import { DENSITIES, type Density } from "../utils/density";
import { readableError } from "../utils/errors";
@@ -160,6 +161,8 @@ export default function CommandPalette({
const inputRef = useRef<HTMLInputElement>(null);
const opener = useRef<HTMLElement | null>(null);
const navigate = useNavigate();
const { pathname } = useLocation();
const favorites = useFavorites();
const canAct = user.role === "admin" || user.role === "operator";
// Ctrl/Cmd+K opens it from anywhere in the app; Escape closes it.
@@ -211,6 +214,24 @@ export default function CommandPalette({
items.push({ key: `page-${p.to}`, category: "Go to", title: p.label, subtitle: p.group, hint: shortcutHintFor(p.to) ?? undefined, path: p.to, keywords: "go open page" });
}
// Pin or unpin the page you are on.
const leaves: NavLeaf[] = [];
for (const entry of visibleNav(user.role)) {
if (isGroup(entry)) leaves.push(...entry.items);
else leaves.push(entry);
}
const here = leaves.filter((l) => isCurrent(pathname, l.to)).sort((a, b) => b.to.length - a.to.length)[0];
if (here) {
const pinned = favorites.includes(here.to);
items.push({
key: "act-favourite",
category: "Actions",
title: pinned ? `Remove ${here.label} from favourites` : `Add ${here.label} to favourites`,
subtitle: "the pages pinned at the top of your menu",
run: () => void toggleFavorite(here.to),
keywords: "favourite favorite pin star bookmark",
});
}
items.push({ key: "act-theme", category: "Actions", title: "Switch between light and dark mode", subtitle: "", run: onToggleTheme, keywords: "theme dark light mode appearance" });
for (const d of DENSITIES) {
items.push({ key: `act-density-${d.value}`, category: "Actions", title: `Density: ${d.label}`, subtitle: "How tightly pages are packed", run: () => onSetDensity(d.value), keywords: "density compact roomy spacing size" });
@@ -293,7 +314,7 @@ export default function CommandPalette({
}
return items;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [user.role, canAct, targets, windows, onToggleTheme, onSetDensity]);
}, [user.role, canAct, targets, windows, onToggleTheme, onSetDensity, pathname, favorites]);
const terms = query.trim().toLowerCase().split(/\s+/).filter(Boolean);
@@ -318,12 +339,19 @@ export default function CommandPalette({
// What is listed: with nothing typed, a few suggestions; otherwise every command that matches, then the data search results.
const items = useMemo(() => {
if (terms.length === 0) {
const pinned = favorites
.map((p) => commands.find((c) => c.key === `page-${p}`))
.filter((c): c is PaletteItem => !!c)
.map((c) => ({ ...c, key: `fav-${c.key}`, category: "Favourites" }));
const wanted = ["page-/", "page-/alerts", "page-/servers", "page-/maintenance", "page-/wall", "act-theme", "act-shortcuts"];
return wanted.map((k) => commands.find((c) => c.key === k)).filter((c): c is PaletteItem => !!c).slice(0, SUGGESTED_LIMIT);
const rest = wanted
.map((k) => commands.find((c) => c.key === k))
.filter((c): c is PaletteItem => !!c && !favorites.includes(c.path ?? ""));
return [...pinned, ...rest].slice(0, SUGGESTED_LIMIT + 3);
}
return [...commands.filter((c) => matches(c, terms)).slice(0, 14), ...found];
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [commands, found, query]);
}, [commands, found, query, favorites]);
useEffect(() => setActiveIndex(0), [items.length, query]);
@@ -358,17 +386,18 @@ export default function CommandPalette({
return (
<button
type="button"
className="btn btn-outline-secondary btn-sm w-100 d-flex align-items-center justify-content-center gap-2"
className="btn btn-outline-secondary btn-sm w-100 d-flex align-items-center justify-content-center gap-2 palette-trigger"
onClick={() => {
opener.current = document.activeElement as HTMLElement | null;
setOpen(true);
}}
title="Search and actions (Ctrl/Cmd+K)"
aria-label="Search and actions"
aria-keyshortcuts="Control+K Meta+K"
>
<IconSearch size={16} />
Search
<kbd className="ms-auto">Ctrl K</kbd>
<span className="palette-text">Search</span>
<kbd className="ms-auto palette-text">Ctrl K</kbd>
</button>
);
}