diff --git a/control/frontend/src/components/Notification.svelte b/control/frontend/src/components/Notification.svelte new file mode 100644 index 0000000..3f16f7e --- /dev/null +++ b/control/frontend/src/components/Notification.svelte @@ -0,0 +1,48 @@ + + +
+ {#each $notifications as n (n.id)} +
+
+ {n.title} + +
+ + {n.message} + +
+
+
+
+ {/each} +
+ + diff --git a/control/frontend/src/routes/+layout.svelte b/control/frontend/src/routes/+layout.svelte index b93e9ba..8a07ae6 100644 --- a/control/frontend/src/routes/+layout.svelte +++ b/control/frontend/src/routes/+layout.svelte @@ -1,7 +1,10 @@ {@render children()} + + \ No newline at end of file diff --git a/control/frontend/src/tailwind.config.js b/control/frontend/src/tailwind.config.js index d4187ee..22263da 100644 --- a/control/frontend/src/tailwind.config.js +++ b/control/frontend/src/tailwind.config.js @@ -213,5 +213,8 @@ module.exports = { 'hover:bg-red-400', 'active:bg-red-500', + + 'hover:bg-stone-600/70', + 'active:bg-stone-500/80', ], } diff --git a/control/frontend/src/ts/stores/notification.ts b/control/frontend/src/ts/stores/notification.ts new file mode 100644 index 0000000..e91ebf1 --- /dev/null +++ b/control/frontend/src/ts/stores/notification.ts @@ -0,0 +1,28 @@ +import { get, writable } from "svelte/store"; + +export type Notification = { + id: number; + title: string; + message: string; + duration: number; + className: string; + type?: "error" | "success" | "info"; +}; + +function createNotifications() { + const { subscribe, update } = writable([]); + + function push(type: "error" | "success" | "info", title: string, message: string = "", className: string = "") { + const id = Date.now(); + const duration = type === "error" ? 8000 : 4000; + update((n) => [...n, { id, title, message, duration, className, type }]); + setTimeout(() => { + update((n) => n.filter((x) => x.id !== id)); + }, duration); + } + const remove = (id: number) => update(n => n.filter(x => x.id !== id)); + + return { subscribe, push, remove }; +} + +export const notifications = createNotifications();