aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Notification
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-01-22 22:26:53 -0800
committerFuwn <[email protected]>2026-01-22 22:26:53 -0800
commitdda52424a3e7a69a01bb745033185429c8d11941 (patch)
tree4c64d6784f668cda38c2097060145c189e3165df /src/lib/Notification
parentformat: Apply Prettier formatting (diff)
downloaddue.moe-dda52424a3e7a69a01bb745033185429c8d11941.tar.xz
due.moe-dda52424a3e7a69a01bb745033185429c8d11941.zip
fix(notifications): Replace svelte-notifications with custom store for Svelte 5
Diffstat (limited to 'src/lib/Notification')
-rw-r--r--src/lib/Notification/NotificationsProvider.svelte31
-rw-r--r--src/lib/Notification/store.ts32
2 files changed, 63 insertions, 0 deletions
diff --git a/src/lib/Notification/NotificationsProvider.svelte b/src/lib/Notification/NotificationsProvider.svelte
new file mode 100644
index 00000000..964317e9
--- /dev/null
+++ b/src/lib/Notification/NotificationsProvider.svelte
@@ -0,0 +1,31 @@
+<script lang="ts">
+ import { notifications } from './store';
+ import EventNotification from './Notification.svelte';
+
+ export let zIndex = 5000;
+
+ const handleRemove = (id: string) => {
+ notifications.remove(id);
+ };
+</script>
+
+<div class="notifications-container" style="z-index: {zIndex};">
+ {#each $notifications as notification (notification.id)}
+ <EventNotification {notification} onRemove={() => handleRemove(notification.id)} />
+ {/each}
+</div>
+
+<slot />
+
+<style>
+ .notifications-container {
+ position: fixed;
+ top: 0;
+ right: 0;
+ pointer-events: none;
+ }
+
+ .notifications-container :global(#notification-container) {
+ pointer-events: auto;
+ }
+</style>
diff --git a/src/lib/Notification/store.ts b/src/lib/Notification/store.ts
new file mode 100644
index 00000000..0cb4cf96
--- /dev/null
+++ b/src/lib/Notification/store.ts
@@ -0,0 +1,32 @@
+import { writable } from 'svelte/store';
+
+export interface Notification {
+ id: string;
+ heading: string;
+ description?: string;
+ duration?: number;
+}
+
+function createNotificationStore() {
+ const { subscribe, update } = writable<Notification[]>([]);
+
+ return {
+ subscribe,
+ add: (notification: Omit<Notification, 'id'>) => {
+ const id = crypto.randomUUID();
+
+ update((notifications) => [...notifications, { ...notification, id }]);
+
+ return id;
+ },
+ remove: (id: string) => {
+ update((notifications) => notifications.filter((n) => n.id !== id));
+ }
+ };
+}
+
+export const notifications = createNotificationStore();
+
+export function addNotification(notification: Omit<Notification, 'id'>) {
+ return notifications.add(notification);
+}