import { createSignal, For, Show } from "solid-js"; export type Notification = { id: string; message: string; progress?: number; total?: number; type?: "info" | "success" | "error"; }; const [notifications, setNotifications] = createSignal([]); const [removingIds, setRemovingIds] = createSignal>(new Set()); export const addNotification = (notification: Omit) => { const id = `notification-${Date.now()}-${Math.random()}`; setNotifications([...notifications(), { ...notification, id }]); return id; }; export const updateNotification = (id: string, updates: Partial) => { setNotifications(notifications().map((n) => (n.id === id ? { ...n, ...updates } : n))); }; export const removeNotification = (id: string) => { setRemovingIds(new Set([...removingIds(), id])); setTimeout(() => { setNotifications(notifications().filter((n) => n.id !== id)); setRemovingIds((ids) => { const newIds = new Set(ids); newIds.delete(id); return newIds; }); }, 250); }; export const NotificationContainer = () => { return (
{(notification) => (
removeNotification(notification.id)} >
{notification.message}
0} fallback={
{notification.progress} MB
} >
{notification.progress}%
)}
); };