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>
33 lines
1.5 KiB
TypeScript
33 lines
1.5 KiB
TypeScript
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} />;
|
|
}
|