Toasts, logo icons, shared table toolbar with search, and a density toggle
Feedback: toasts confirm common actions, and a page's error or success message that appears out of view is also shown as a toast. Icons: the tab, app and home-screen icons are the house from the logo; a dev instance gets a coloured dot on its tab icon. Tables: Secrets, Admin Links, IP Addresses and Alerts share one toolbar (search, filters, row count, actions, Export CSV); twelve more tables get a multi-word search box; long tables keep their column headings in view on wide screens. Density: Compact / Normal / Roomy in the user menu, remembered per browser. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7d56ad18b7
commit
617dc1ea2f
56 files changed
+757
-158
No files matched your search
@@ -0,0 +1,42 @@
|
||||
// How tightly the pages are packed: Compact fits more on screen, Roomy is easier to read on a big monitor or a tablet.
|
||||
// Chosen per browser (the styles key off the data-density attribute on <html>); Normal is the original look.
|
||||
|
||||
export type Density = "compact" | "normal" | "roomy";
|
||||
|
||||
export const DENSITIES: { value: Density; label: string }[] = [
|
||||
{ value: "compact", label: "Compact" },
|
||||
{ value: "normal", label: "Normal" },
|
||||
{ value: "roomy", label: "Roomy" },
|
||||
];
|
||||
|
||||
const KEY = "hlm-density";
|
||||
|
||||
export function getDensity(): Density {
|
||||
const value = document.documentElement.getAttribute("data-density");
|
||||
return value === "compact" || value === "roomy" ? value : "normal";
|
||||
}
|
||||
|
||||
function apply(density: Density): void {
|
||||
if (density === "normal") document.documentElement.removeAttribute("data-density");
|
||||
else document.documentElement.setAttribute("data-density", density);
|
||||
}
|
||||
|
||||
/** Called once at start-up, before anything is drawn, so the page never flashes in the wrong density. */
|
||||
export function applyStoredDensity(): void {
|
||||
try {
|
||||
const stored = localStorage.getItem(KEY);
|
||||
if (stored === "compact" || stored === "roomy") apply(stored);
|
||||
} catch {
|
||||
// storage blocked: the normal look
|
||||
}
|
||||
}
|
||||
|
||||
export function setDensity(density: Density): void {
|
||||
apply(density);
|
||||
try {
|
||||
if (density === "normal") localStorage.removeItem(KEY);
|
||||
else localStorage.setItem(KEY, density);
|
||||
} catch {
|
||||
// not remembered; it still applies for this visit
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,39 @@ function applyEnvironment(look: EnvironmentLook | null): void {
|
||||
root.setAttribute("data-env", look.name || "custom");
|
||||
document.title = look.name ? `[${look.name}] ${BASE_TITLE}` : BASE_TITLE;
|
||||
document.querySelector('meta[name="theme-color"]')?.setAttribute("content", look.color);
|
||||
tintFavicon(look.color);
|
||||
}
|
||||
|
||||
/** The tab icon gets a dot in the environment's colour in its corner, so this tab stands out among several. */
|
||||
function tintFavicon(color: string): void {
|
||||
const links = document.querySelectorAll<HTMLLinkElement>('link[rel~="icon"]');
|
||||
if (links.length === 0) return;
|
||||
const image = new Image();
|
||||
image.onload = () => {
|
||||
try {
|
||||
const size = 64;
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = canvas.height = size;
|
||||
const ctx = canvas.getContext("2d");
|
||||
if (!ctx) return;
|
||||
ctx.drawImage(image, 0, 0, size, size);
|
||||
ctx.beginPath();
|
||||
ctx.arc(size - 19, size - 19, 18, 0, Math.PI * 2);
|
||||
ctx.fillStyle = color;
|
||||
ctx.fill();
|
||||
ctx.lineWidth = 5;
|
||||
ctx.strokeStyle = "#ffffff";
|
||||
ctx.stroke();
|
||||
const href = canvas.toDataURL("image/png");
|
||||
links.forEach((link) => {
|
||||
link.href = href;
|
||||
link.removeAttribute("sizes");
|
||||
});
|
||||
} catch {
|
||||
// The plain icon stays; this is only a nicety.
|
||||
}
|
||||
};
|
||||
image.src = "/icon-192.png";
|
||||
}
|
||||
|
||||
/** Whether white text on this colour would be hard to read. */
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
// Short messages that appear in a corner of the screen and go away by themselves — for the result of something you just did
|
||||
// when the place you did it may no longer be in view. Anything can call toast.success() / toast.error() / toast.info(); one
|
||||
// <ToastHost /> (mounted once, in App) draws them.
|
||||
|
||||
export type ToastKind = "success" | "error" | "info";
|
||||
|
||||
export interface ToastItem {
|
||||
id: number;
|
||||
kind: ToastKind;
|
||||
message: string;
|
||||
}
|
||||
|
||||
let nextId = 1;
|
||||
let items: ToastItem[] = [];
|
||||
const listeners = new Set<(items: ToastItem[]) => void>();
|
||||
|
||||
function emit() {
|
||||
for (const l of listeners) l(items);
|
||||
}
|
||||
|
||||
export function subscribeToasts(listener: (items: ToastItem[]) => void): () => void {
|
||||
listeners.add(listener);
|
||||
listener(items);
|
||||
return () => {
|
||||
listeners.delete(listener);
|
||||
};
|
||||
}
|
||||
|
||||
export function dismissToast(id: number): void {
|
||||
items = items.filter((t) => t.id !== id);
|
||||
emit();
|
||||
}
|
||||
|
||||
function show(kind: ToastKind, message: string): void {
|
||||
const text = message.trim();
|
||||
if (!text) return;
|
||||
// The same message twice in a row is one toast, not two.
|
||||
if (items.some((t) => t.kind === kind && t.message === text)) return;
|
||||
// A handful at most: the newest few are what matter.
|
||||
items = [...items, { id: nextId++, kind, message: text }].slice(-4);
|
||||
emit();
|
||||
}
|
||||
|
||||
export const toast = {
|
||||
success: (message: string) => show("success", message),
|
||||
error: (message: string) => show("error", message),
|
||||
info: (message: string) => show("info", message),
|
||||
};
|
||||
Reference in new issue
Block a user