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

+38 -2
View File
@@ -1,9 +1,45 @@
import { Router } from "express";
import { eq } from "drizzle-orm";
import { z } from "zod";
import { db } from "../db/client.js";
import { users } from "../db/schema.js";
import { requireAuth } from "../auth/middleware.js";
import { asyncHandler } from "../utils/asyncHandler.js";
export const meRouter = Router();
/** The most pages anyone can pin: enough for a working set, not a second menu. */
export const MAX_FAVORITES = 24;
/** What is stored, read back as a list. Anything that isn't one is no favourites rather than an error. */
export function parseFavorites(stored: string | null): string[] {
if (!stored) return [];
try {
const value = JSON.parse(stored);
return Array.isArray(value) ? value.filter((v): v is string => typeof v === "string").slice(0, MAX_FAVORITES) : [];
} catch {
return [];
}
}
meRouter.get("/", requireAuth, (req, res) => {
const { id, email, name, role, oidcSub } = req.currentUser!;
res.json({ user: { id, sub: oidcSub, email, name, role } });
const { id, email, name, role, oidcSub, favorites } = req.currentUser!;
res.json({ user: { id, sub: oidcSub, email, name, role, favorites: parseFavorites(favorites) } });
});
// Paths inside the app only: a slash, then letters, digits, dashes, underscores and further slashes. Which of them are real pages is
// the menu's business; a favourite for a page that is gone, or that this person's role can't open, is simply not shown.
const favoritesSchema = z.object({
paths: z.array(z.string().regex(/^\/[A-Za-z0-9\-_/]{0,80}$/, "Not a page path")).max(MAX_FAVORITES),
});
// Replaces the signed-in person's pinned pages. Only ever their own.
meRouter.put("/favorites", requireAuth, asyncHandler(async (req, res) => {
const parsed = favoritesSchema.safeParse(req.body);
if (!parsed.success) {
return res.status(400).json({ error: "invalid_body", message: `Pin up to ${MAX_FAVORITES} pages, by their path.`, details: parsed.error.flatten() });
}
const paths = [...new Set(parsed.data.paths)];
await db.update(users).set({ favorites: JSON.stringify(paths) }).where(eq(users.id, req.currentUser!.id));
res.json({ favorites: paths });
}));