···
import { createSignal, For, Show } from "solid-js";
2
+
import { createStore } from "solid-js/store";
export type Notification = {
···
type?: "info" | "success" | "error";
11
-
const [notifications, setNotifications] = createSignal<Notification[]>([]);
12
+
const [notifications, setNotifications] = createStore<Notification[]>([]);
const [removingIds, setRemovingIds] = createSignal<Set<string>>(new Set());
export const addNotification = (notification: Omit<Notification, "id">) => {
const id = `notification-${Date.now()}-${Math.random()}`;
16
-
setNotifications([...notifications(), { ...notification, id }]);
17
+
setNotifications(notifications.length, { ...notification, id });
export const updateNotification = (id: string, updates: Partial<Notification>) => {
21
-
setNotifications(notifications().map((n) => (n.id === id ? { ...n, ...updates } : n)));
22
+
setNotifications((n) => n.id === id, updates);
export const removeNotification = (id: string) => {
setRemovingIds(new Set([...removingIds(), id]));
27
-
setNotifications(notifications().filter((n) => n.id !== id));
28
+
setNotifications((n) => n.filter((notification) => notification.id !== id));
setRemovingIds((ids) => {
const newIds = new Set(ids);
···
export const NotificationContainer = () => {
<div class="pointer-events-none fixed bottom-4 left-4 z-50 flex flex-col gap-2">
39
-
<For each={notifications()}>
40
+
<For each={notifications}>
class="dark:bg-dark-300 dark:shadow-dark-700 pointer-events-auto flex min-w-64 flex-col gap-2 rounded-lg border-[0.5px] border-neutral-300 bg-neutral-50 p-3 shadow-md select-none dark:border-neutral-700"