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:
bobbanandClaude Sonnet 5.5 committed 2026-10-14 23:39:19 +02:00
1 parent 7d56ad18b7
commit 617dc1ea2f
56 files changed
+757 -158

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
import { useEffect, useRef } from "react";
import { toast } from "../utils/toast";
function Notice({ message, kind, className = "" }: { message: string | null | undefined; kind: "danger" | "success"; className?: string }) {
const ref = useRef<HTMLDivElement>(null);
// A message that appears where you are looking needs nothing more. One that appears out of view — above after scrolling, or
// far down a long page — would otherwise go unseen, so it is also raised as a toast.
useEffect(() => {
if (!message) return;
const rect = ref.current?.getBoundingClientRect();
const inView = !!rect && rect.height > 0 && rect.bottom > 0 && rect.top < window.innerHeight;
if (!inView) (kind === "danger" ? toast.error : toast.success)(message);
}, [message, kind]);
if (!message) return null;
return (
<div ref={ref} className={`alert alert-${kind} ${className}`.trim()} role={kind === "danger" ? "alert" : "status"}>
{message}
</div>
);
}
/** The usual red message under a page title. Also shown as a toast when it appears out of view. */
export function ErrorNotice({ error, className }: { error: string | null | undefined; className?: string }) {
return <Notice message={error} kind="danger" className={className} />;
}
/** The usual green message after something worked. Also shown as a toast when it appears out of view. */
export function SuccessNotice({ notice, className }: { notice: string | null | undefined; className?: string }) {
return <Notice message={notice} kind="success" className={className} />;
}
+2 -1
View File
@@ -8,6 +8,7 @@ import { readableError } from "../utils/errors";
import Pagination from "./Pagination";
import SortableTh from "./SortableTh";
import { confirmDialog } from "../utils/dialogs";
import { ErrorNotice } from "./Notice";
const PRESETS: { key: string; label: string; from: number; to: number }[] = [
{ key: "well-known", label: "1–1024 (well-known)", from: 1, to: 1024 },
@@ -235,7 +236,7 @@ export default function ServerPorts({
</div>
<div className="card-body pb-2">
{error && <div className="alert alert-danger">{error}</div>}
<ErrorNotice error={error} />
{data && (
<div className="text-secondary small mb-2">
+2 -1
View File
@@ -3,6 +3,7 @@ import { Link } from "react-router-dom";
import { api } from "../api/client";
import { normalizeTagInput, tagBadge, useTagColors } from "../utils/tags";
import { readableError } from "../utils/errors";
import { ErrorNotice } from "./Notice";
export function TagBadges({ tags, linked = false }: { tags: string[]; linked?: boolean }) {
const colors = useTagColors();
@@ -99,7 +100,7 @@ export default function ServerTags({
return (
<div className="card mb-3">
<div className="card-body">
{error && <div className="alert alert-danger">{error}</div>}
<ErrorNotice error={error} />
<label className="form-label">Tags</label>
<div className="d-flex flex-wrap align-items-center gap-1 mb-2">
{draftTags.map((tag) => {
+80
View File
@@ -0,0 +1,80 @@
import type { ReactNode } from "react";
import { IconSearch } from "@tabler/icons-react";
/** The search box every table uses, so they look and behave alike. Esc clears it. */
export function SearchBox({
value,
onChange,
placeholder = "Search…",
className = "",
}: {
value: string;
onChange: (value: string) => void;
placeholder?: string;
className?: string;
}) {
return (
<div className={`input-icon table-search ${className}`.trim()}>
<span className="input-icon-addon">
<IconSearch size={16} />
</span>
<input
type="search"
className="form-control form-control-sm"
placeholder={placeholder}
aria-label={placeholder}
value={value}
onChange={(e) => onChange(e.target.value)}
onKeyDown={(e) => e.key === "Escape" && value && onChange("")}
/>
</div>
);
}
/**
* The strip across the top of a table card: search and filters on the left, how many rows are showing, then the table's own
* actions (Add, Sync…) and Export CSV last on the right. Every table that can be searched uses this, in this order.
*/
export default function TableToolbar({
search,
onSearch,
placeholder,
filters,
actions,
onExport,
exportDisabled,
shown,
total,
}: {
search: string;
onSearch: (value: string) => void;
placeholder?: string;
/** Selects and tick-boxes that narrow the rows, shown beside the search box. */
filters?: ReactNode;
/** Buttons for this table (Add, Sync…), shown before Export CSV. */
actions?: ReactNode;
onExport?: () => void;
exportDisabled?: boolean;
/** Rows showing now, and rows there are in all — shown as "12 of 40" once something narrows them. */
shown?: number;
total?: number;
}) {
const narrowed = shown !== undefined && total !== undefined && shown !== total;
return (
<div className="card-header table-toolbar">
<div className="table-toolbar-inner">
<SearchBox value={search} onChange={onSearch} placeholder={placeholder} />
{filters}
{narrowed && <span className="text-secondary small">{shown} of {total}</span>}
<div className="table-toolbar-actions">
{actions}
{onExport && (
<button type="button" className="btn btn-sm btn-outline-secondary" onClick={onExport} disabled={exportDisabled}>
Export CSV
</button>
)}
</div>
</div>
</div>
);
}
+48
View File
@@ -0,0 +1,48 @@
import { useEffect, useState } from "react";
import { createPortal } from "react-dom";
import { IconAlertTriangle, IconCircleCheck, IconInfoCircle, IconX } from "@tabler/icons-react";
import { dismissToast, subscribeToasts, type ToastItem } from "../utils/toast";
const LIFETIME_MS = { success: 4_500, info: 6_000, error: 9_000 } as const;
function ToastView({ item }: { item: ToastItem }) {
const [paused, setPaused] = useState(false);
// Goes away by itself — unless the pointer is on it, so a long message can be read.
useEffect(() => {
if (paused) return;
const timer = setTimeout(() => dismissToast(item.id), LIFETIME_MS[item.kind]);
return () => clearTimeout(timer);
}, [paused, item.id, item.kind]);
const Icon = item.kind === "success" ? IconCircleCheck : item.kind === "error" ? IconAlertTriangle : IconInfoCircle;
return (
<div
className={`toast-item toast-${item.kind}`}
role={item.kind === "error" ? "alert" : "status"}
onMouseEnter={() => setPaused(true)}
onMouseLeave={() => setPaused(false)}
>
<Icon size={18} className="flex-shrink-0 mt-1" />
<div className="flex-fill">{item.message}</div>
<button type="button" className="toast-close" aria-label="Dismiss" onClick={() => dismissToast(item.id)}>
<IconX size={16} />
</button>
</div>
);
}
/** Draws the toasts raised through utils/toast. Mount once, near the root. */
export default function ToastHost() {
const [items, setItems] = useState<ToastItem[]>([]);
useEffect(() => subscribeToasts(setItems), []);
if (items.length === 0) return null;
return createPortal(
<div className="toast-stack" aria-live="polite">
{items.map((t) => (
<ToastView key={t.id} item={t} />
))}
</div>,
document.body,
);
}