From dda52424a3e7a69a01bb745033185429c8d11941 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 22 Jan 2026 22:26:53 -0800 Subject: fix(notifications): Replace svelte-notifications with custom store for Svelte 5 --- src/lib/List/Anime/CompletedAnimeList.svelte | 4 +-- src/lib/List/Anime/DueAnimeList.svelte | 4 +-- src/lib/List/Anime/UpcomingAnimeList.svelte | 4 +-- src/lib/List/Manga/MangaListTemplate.svelte | 4 +-- src/lib/Notification/NotificationsProvider.svelte | 31 ++++++++++++++++++++++ src/lib/Notification/store.ts | 32 +++++++++++++++++++++++ src/lib/Settings/Categories/Debug.svelte | 4 +-- src/lib/Settings/Categories/RSSFeeds.svelte | 4 +-- src/lib/Settings/Categories/SettingSync.svelte | 4 +-- src/routes/+layout.svelte | 7 +++-- 10 files changed, 73 insertions(+), 25 deletions(-) create mode 100644 src/lib/Notification/NotificationsProvider.svelte create mode 100644 src/lib/Notification/store.ts (limited to 'src') diff --git a/src/lib/List/Anime/CompletedAnimeList.svelte b/src/lib/List/Anime/CompletedAnimeList.svelte index 4245525d..8e914ef6 100644 --- a/src/lib/List/Anime/CompletedAnimeList.svelte +++ b/src/lib/List/Anime/CompletedAnimeList.svelte @@ -6,7 +6,7 @@ import lastPruneTimes from '$stores/lastPruneTimes'; import settings from '$stores/settings'; import AnimeList from './AnimeListTemplate.svelte'; - import { getNotificationsContext } from 'svelte-notifications'; + import { addNotification } from '$lib/Notification/store'; import locale from '$stores/locale'; import identity from '$stores/identity'; import sampleAnime from '$lib/Data/Static/SampleMedia/anime.json'; @@ -19,8 +19,6 @@ }; export let dummy = false; export let disableFilter = false; - - const { addNotification } = getNotificationsContext(); let animeLists: Promise; let startTime: number; let endTime: number; diff --git a/src/lib/List/Anime/DueAnimeList.svelte b/src/lib/List/Anime/DueAnimeList.svelte index 95be3b6c..2db8da65 100644 --- a/src/lib/List/Anime/DueAnimeList.svelte +++ b/src/lib/List/Anime/DueAnimeList.svelte @@ -8,13 +8,11 @@ import AnimeList from './AnimeListTemplate.svelte'; import type { SubsPlease } from '$lib/Media/Anime/Airing/Subtitled/subsPlease'; import { injectAiringTime } from '$lib/Media/Anime/Airing/Subtitled/match'; - import { getNotificationsContext } from 'svelte-notifications'; + import { addNotification } from '$lib/Notification/store'; import locale from '$stores/locale'; import identity from '$stores/identity'; export let user: AniListAuthorisation; - - const { addNotification } = getNotificationsContext(); let animeLists: Promise; let startTime: number; let endTime: number; diff --git a/src/lib/List/Anime/UpcomingAnimeList.svelte b/src/lib/List/Anime/UpcomingAnimeList.svelte index 7b01af86..a0645320 100644 --- a/src/lib/List/Anime/UpcomingAnimeList.svelte +++ b/src/lib/List/Anime/UpcomingAnimeList.svelte @@ -7,15 +7,13 @@ import AnimeList from './AnimeListTemplate.svelte'; import settings from '$stores/settings'; import type { SubsPlease } from '$lib/Media/Anime/Airing/Subtitled/subsPlease'; - import { getNotificationsContext } from 'svelte-notifications'; + import { addNotification } from '$lib/Notification/store'; import locale from '$stores/locale'; import identity from '$stores/identity'; import { injectAiringTime } from '$lib/Media/Anime/Airing/Subtitled/match'; import revalidateAnime from '$stores/revalidateAnime'; export let user: AniListAuthorisation; - - const { addNotification } = getNotificationsContext(); let animeLists: Promise; let startTime: number; let endTime: number; diff --git a/src/lib/List/Manga/MangaListTemplate.svelte b/src/lib/List/Manga/MangaListTemplate.svelte index b2d95dc5..83c491c8 100644 --- a/src/lib/List/Manga/MangaListTemplate.svelte +++ b/src/lib/List/Manga/MangaListTemplate.svelte @@ -13,7 +13,7 @@ import Error from '$lib/Error/RateLimited.svelte'; import CleanMangaList from './CleanMangaList.svelte'; import { incrementMediaProgress } from '$lib/Media/Anime/cache'; - import { getNotificationsContext } from 'svelte-notifications'; + import { addNotification } from '$lib/Notification/store'; import { options } from '$lib/Notification/options'; import Skeleton from '$lib/Loading/Skeleton.svelte'; import locale from '$stores/locale'; @@ -32,8 +32,6 @@ export let due: boolean; export let dummy = $settings.debugDummyLists || false; export let disableFilter = false; - - const { addNotification } = getNotificationsContext(); const authorised = privilegedUser($identity.id); let mangaLists: Promise; let startTime: number; 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 @@ + + +
+ {#each $notifications as notification (notification.id)} + handleRemove(notification.id)} /> + {/each} +
+ + + + 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([]); + + return { + subscribe, + add: (notification: Omit) => { + 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) { + return notifications.add(notification); +} diff --git a/src/lib/Settings/Categories/Debug.svelte b/src/lib/Settings/Categories/Debug.svelte index 379b27d0..852db4f3 100644 --- a/src/lib/Settings/Categories/Debug.svelte +++ b/src/lib/Settings/Categories/Debug.svelte @@ -1,6 +1,6 @@