import { createSignal, For, Show } from "solid-js"; import { createStore } from "solid-js/store"; export type Notification = { id: string; message: string; progress?: number; total?: number; type?: "info" | "success" | "error"; }; const [notifications, setNotifications] = createStore([]); const [removingIds, setRemovingIds] = createSignal>(new Set()); export const addNotification = (notification: Omit) => { const id = `notification-${Date.now()}-${Math.random()}`; setNotifications(notifications.length, { ...notification, id }); return id; }; export const updateNotification = (id: string, updates: Partial) => { setNotifications((n) => n.id === id, updates); }; export const removeNotification = (id: string) => { setRemovingIds(new Set([...removingIds(), id])); setTimeout(() => { setNotifications((n) => n.filter((notification) => notification.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}%
)}
); };