diff options
| author | Fuwn <[email protected]> | 2024-01-11 22:07:08 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-01-11 22:07:08 -0800 |
| commit | bcdaf7d9214a16473b70bd1078a047dad76ab870 (patch) | |
| tree | 44f11a4a5c0707aeb83084958c4f38a42d8994e8 /src/lib | |
| parent | fix(api): un-share some caches (diff) | |
| download | due.moe-bcdaf7d9214a16473b70bd1078a047dad76ab870.tar.xz due.moe-bcdaf7d9214a16473b70bd1078a047dad76ab870.zip | |
feat(list): recache notifications
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/AniList/media.ts | 21 | ||||
| -rw-r--r-- | src/lib/List/Anime/CompletedAnimeList.svelte | 6 | ||||
| -rw-r--r-- | src/lib/List/Anime/DueAnimeList.svelte | 15 | ||||
| -rw-r--r-- | src/lib/List/Anime/UpcomingAnimeList.svelte | 7 | ||||
| -rw-r--r-- | src/lib/List/Manga/MangaListTemplate.svelte | 16 | ||||
| -rw-r--r-- | src/lib/Notification/options.ts | 2 |
6 files changed, 43 insertions, 24 deletions
diff --git a/src/lib/AniList/media.ts b/src/lib/AniList/media.ts index 2becc0d5..e65c90cd 100644 --- a/src/lib/AniList/media.ts +++ b/src/lib/AniList/media.ts @@ -4,6 +4,7 @@ import anime from '$stores/anime'; import manga from '$stores/manga'; import settings from '$stores/settings'; import lastPruneTimes from '$stores/lastPruneTimes'; +import { options as getOptions, type Options } from '$lib/Notification/options'; export enum Type { Anime, @@ -145,25 +146,35 @@ interface CollectionOptions { includeCompleted?: boolean; forcePrune?: boolean; all?: boolean; + addNotification?: (preferences: Options) => void; + notificationType?: string; } interface NonNullCollectionOptions { includeCompleted: boolean; forcePrune: boolean; all?: boolean; + addNotification?: (preferences: Options) => void; + notificationType?: string; } const assignDefaultOptions = (options: CollectionOptions) => { const nonNullOptions: NonNullCollectionOptions = { includeCompleted: false, forcePrune: false, - all: false + all: false, + addNotification: undefined, + notificationType: undefined }; if (options.includeCompleted !== undefined) nonNullOptions.includeCompleted = options.includeCompleted; if (options.forcePrune !== undefined) nonNullOptions.forcePrune = options.forcePrune; if (options.all !== undefined) nonNullOptions.all = options.all; + if (options.addNotification !== undefined) + nonNullOptions.addNotification = options.addNotification; + if (options.notificationType !== undefined) + nonNullOptions.notificationType = options.notificationType; return nonNullOptions; }; @@ -233,6 +244,14 @@ export const mediaListCollection = async ( ) ); + if (options.addNotification) + options.addNotification( + getOptions({ + heading: options.notificationType ? options.notificationType : Type[type], + description: 'Re-cached media lists from AniList' + }) + ); + return flattenLists(userIdResponse['data']['MediaListCollection']['lists'], options.all); }; diff --git a/src/lib/List/Anime/CompletedAnimeList.svelte b/src/lib/List/Anime/CompletedAnimeList.svelte index 0c610216..bd9df8d7 100644 --- a/src/lib/List/Anime/CompletedAnimeList.svelte +++ b/src/lib/List/Anime/CompletedAnimeList.svelte @@ -6,17 +6,21 @@ import lastPruneTimes from '$stores/lastPruneTimes'; import settings from '$stores/settings'; import AnimeList from './AnimeListTemplate.svelte'; + import { getNotificationsContext } from 'svelte-notifications'; export let user: AniListAuthorisation; export let identity: UserIdentity; + const { addNotification } = getNotificationsContext(); let animeLists: Promise<Media[]>; let startTime: number; let endTime: number; onMount(async () => { startTime = performance.now(); - animeLists = mediaListCollection(user, identity, Type.Anime, $anime, $lastPruneTimes.anime); + animeLists = mediaListCollection(user, identity, Type.Anime, $anime, $lastPruneTimes.anime, { + addNotification + }); }); const cleanMedia = (anime: Media[]) => { diff --git a/src/lib/List/Anime/DueAnimeList.svelte b/src/lib/List/Anime/DueAnimeList.svelte index 750d773b..f4439c8b 100644 --- a/src/lib/List/Anime/DueAnimeList.svelte +++ b/src/lib/List/Anime/DueAnimeList.svelte @@ -8,7 +8,6 @@ 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 { options } from '$lib/Notification/options'; import { getNotificationsContext } from 'svelte-notifications'; export let user: AniListAuthorisation; @@ -23,20 +22,16 @@ startTime = performance.now(); endTime = -1; animeLists = mediaListCollection(user, identity, Type.Anime, $anime, $lastPruneTimes.anime, { - forcePrune: true + forcePrune: true, + addNotification }); - - addNotification( - options({ - heading: 'Anime', - description: 'Re-cached from AniList' - }) - ); }, $settings.cacheMinutes * 1000 * 60); onMount(async () => { startTime = performance.now(); - animeLists = mediaListCollection(user, identity, Type.Anime, $anime, $lastPruneTimes.anime); + animeLists = mediaListCollection(user, identity, Type.Anime, $anime, $lastPruneTimes.anime, { + addNotification + }); }); onDestroy(() => clearInterval(keyCacher)); diff --git a/src/lib/List/Anime/UpcomingAnimeList.svelte b/src/lib/List/Anime/UpcomingAnimeList.svelte index 46a42e1d..cdcf23c0 100644 --- a/src/lib/List/Anime/UpcomingAnimeList.svelte +++ b/src/lib/List/Anime/UpcomingAnimeList.svelte @@ -7,17 +7,22 @@ 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'; export let user: AniListAuthorisation; export let identity: UserIdentity; + const { addNotification } = getNotificationsContext(); let animeLists: Promise<Media[]>; let startTime: number; let endTime: number; onMount(async () => { startTime = performance.now(); - animeLists = mediaListCollection(user, identity, Type.Anime, $anime, $lastPruneTimes.anime); + animeLists = mediaListCollection(user, identity, Type.Anime, $anime, $lastPruneTimes.anime, { + addNotification, + notificationType: 'Upcoming Episodes' + }); }); const cleanMedia = ( diff --git a/src/lib/List/Manga/MangaListTemplate.svelte b/src/lib/List/Manga/MangaListTemplate.svelte index 97f020be..388ef543 100644 --- a/src/lib/List/Manga/MangaListTemplate.svelte +++ b/src/lib/List/Manga/MangaListTemplate.svelte @@ -14,7 +14,6 @@ import authorisedJson from '$lib/authorised.json'; import { incrementMediaProgress } from '$lib/Media/Anime/cache'; import { getNotificationsContext } from 'svelte-notifications'; - import { options } from '$lib/Notification/options'; export let user: AniListAuthorisation; export let identity: UserIdentity; @@ -36,19 +35,16 @@ const keyCacher = setInterval(() => { startTime = performance.now(); endTime = -1; - mangaLists = mediaListCollection(user, identity, Type.Manga, $manga, $lastPruneTimes.manga); - - addNotification( - options({ - heading: 'Manga', - description: 'Re-cached media lists from AniList' - }) - ); + mangaLists = mediaListCollection(user, identity, Type.Manga, $manga, $lastPruneTimes.manga, { + addNotification + }); }, $settings.cacheMinutes * 1000 * 60); onMount(async () => { startTime = performance.now(); - mangaLists = mediaListCollection(user, identity, Type.Manga, $manga, $lastPruneTimes.manga); + mangaLists = mediaListCollection(user, identity, Type.Manga, $manga, $lastPruneTimes.manga, { + addNotification + }); }); onDestroy(() => clearInterval(keyCacher)); diff --git a/src/lib/Notification/options.ts b/src/lib/Notification/options.ts index f14e0d25..a9896540 100644 --- a/src/lib/Notification/options.ts +++ b/src/lib/Notification/options.ts @@ -1,6 +1,6 @@ type Position = 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left'; -interface Options { +export interface Options { heading: string | number; description: string | number | undefined; position: Position; |