From 1b71b6a1197967271528fd0d5b9ff5fc9a1f3c26 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 11 Jan 2024 18:45:31 -0800 Subject: feat: notifications --- src/lib/Notification/Notification.svelte | 112 +++++++++++++++++++++++++++++++ src/lib/Notification/options.ts | 19 ++++++ src/lib/Settings/Categories/Debug.svelte | 26 ++++++- src/routes/+layout.svelte | 28 ++++---- 4 files changed, 171 insertions(+), 14 deletions(-) create mode 100644 src/lib/Notification/Notification.svelte create mode 100644 src/lib/Notification/options.ts (limited to 'src') diff --git a/src/lib/Notification/Notification.svelte b/src/lib/Notification/Notification.svelte new file mode 100644 index 00000000..9612d526 --- /dev/null +++ b/src/lib/Notification/Notification.svelte @@ -0,0 +1,112 @@ + + +
+ {#if notification.description} +
+ {@html notification.heading} + + {@html notification.description} + +
+ +
+ +
+
+ {:else} +
+ {@html notification.heading} + +     + +
+ +
+
+ {/if} +
+ + diff --git a/src/lib/Notification/options.ts b/src/lib/Notification/options.ts new file mode 100644 index 00000000..f14e0d25 --- /dev/null +++ b/src/lib/Notification/options.ts @@ -0,0 +1,19 @@ +type Position = 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left'; + +interface Options { + heading: string | number; + description: string | number | undefined; + position: Position; + duration: number; + id: string; +} + +export const options = (preferences: { [key: string]: number | string }): Options => { + return { + position: (preferences.position || 'top-right') as Position, + duration: Number(preferences.duration || 3000), + heading: preferences.heading || 'Notification', + description: preferences.description || undefined, + id: Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15) + }; +}; diff --git a/src/lib/Settings/Categories/Debug.svelte b/src/lib/Settings/Categories/Debug.svelte index 5f6be96b..c21b6dd7 100644 --- a/src/lib/Settings/Categories/Debug.svelte +++ b/src/lib/Settings/Categories/Debug.svelte @@ -1,16 +1,38 @@ - + Resets all settings present on this page to their default values

- + Resets all of your settings to their default values and clears both AniList media list and manga data caches diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index e1df9c9d..52d1b8ba 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -10,6 +10,8 @@ import { fly } from 'svelte/transition'; import { readable, type Readable } from 'svelte/store'; import { navigating } from '$app/stores'; + import Notifications from 'svelte-notifications'; + import Notification from '$lib/Notification/Notification.svelte'; export let data; @@ -99,18 +101,20 @@

- {#key data.url} -

- -
- {/key} + + {#key data.url} +
+ +
+ {/key} +