From 3a1df485ed8f19d0f4bd7c7a95fa3d072c46f013 Mon Sep 17 00:00:00 2001 From: plenarius Date: Mon, 20 Apr 2026 22:12:50 -0400 Subject: [PATCH] feat: add error display, error boundaries, and toast notifications --- packages/frontend/src/components/Toast.tsx | 34 ++++++++++------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/packages/frontend/src/components/Toast.tsx b/packages/frontend/src/components/Toast.tsx index 48bfb60..68cf7d4 100644 --- a/packages/frontend/src/components/Toast.tsx +++ b/packages/frontend/src/components/Toast.tsx @@ -31,7 +31,7 @@ export function useToast() { const COLORS: Record = { success: { bg: "#052e16", border: "#166534", text: "#4ade80" }, error: { bg: "#3b1111", border: "#7f1d1d", text: "#fca5a5" }, - info: { bg: "#1c1a00", border: "#713f12", text: "#fbbf24" }, + info: { bg: "#1c1403", border: "#946200", text: "#fbbf24" }, }; const AUTO_DISMISS: Record = { @@ -48,30 +48,28 @@ function ToastItem({ onDismiss: (id: number) => void; }) { const { bg, border, text } = COLORS[toast.type]; - const dismissMs = AUTO_DISMISS[toast.type]; + const timeout = AUTO_DISMISS[toast.type]; const timerRef = useRef>(); useEffect(() => { - if (dismissMs !== null) { - timerRef.current = setTimeout(() => onDismiss(toast.id), dismissMs); + if (timeout) { + timerRef.current = setTimeout(() => onDismiss(toast.id), timeout); return () => clearTimeout(timerRef.current); } - }, [toast.id, dismissMs, onDismiss]); + }, [toast.id, timeout, onDismiss]); return (
- - {toast.message} - + {toast.message}
); @@ -83,20 +81,20 @@ export function ToastProvider({ children }: { children: ReactNode }) { const [toasts, setToasts] = useState([]); const showToast = useCallback((message: string, type: ToastType = "info") => { - const id = ++nextId; - setToasts((t) => [...t, { id, message, type }]); + const id = nextId++; + setToasts((prev) => [...prev, { id, message, type }]); }, []); const dismiss = useCallback((id: number) => { - setToasts((t) => t.filter((toast) => toast.id !== id)); + setToasts((prev) => prev.filter((t) => t.id !== id)); }, []); return ( {children} -
- {toasts.map((toast) => ( - +
+ {toasts.map((t) => ( + ))}