diff options
| author | Fuwn <[email protected]> | 2026-03-28 08:33:47 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-03-28 08:33:47 +0000 |
| commit | 64ff00d5b3e93d780f2f3d65eb50595bafc1cb18 (patch) | |
| tree | c44de213b7d6d541e3d7519d030094af4dd292a5 /src/lib | |
| parent | fix(anilist): fall back to persisted media list cache (diff) | |
| download | due.moe-64ff00d5b3e93d780f2f3d65eb50595bafc1cb18.tar.xz due.moe-64ff00d5b3e93d780f2f3d65eb50595bafc1cb18.zip | |
fix(anilist): restore completed list filters
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/Data/AniList/cacheHydration.ts | 4 | ||||
| -rw-r--r-- | src/lib/Data/AniList/media.ts | 48 | ||||
| -rw-r--r-- | src/lib/List/Anime/CleanAnimeList.svelte | 18 | ||||
| -rw-r--r-- | src/lib/List/Anime/CompletedAnimeList.svelte | 1 | ||||
| -rw-r--r-- | src/lib/List/Manga/CleanMangaList.svelte | 16 |
5 files changed, 61 insertions, 26 deletions
diff --git a/src/lib/Data/AniList/cacheHydration.ts b/src/lib/Data/AniList/cacheHydration.ts index 434d2a82..ac3b4d72 100644 --- a/src/lib/Data/AniList/cacheHydration.ts +++ b/src/lib/Data/AniList/cacheHydration.ts @@ -6,6 +6,8 @@ import localforage from "localforage"; type MediaCacheKind = "anime" | "manga"; +const cacheStorageKey = (kind: MediaCacheKind) => `${kind}:v2`; + interface StoredLastPruneTimes { anime: number; chapters: number; @@ -32,7 +34,7 @@ export const hydrateMediaListCache = (kind: MediaCacheKind) => { const promise = (async () => { const [cache, pruneTimes] = await Promise.all([ - localforage.getItem<string>(kind), + localforage.getItem<string>(cacheStorageKey(kind)), localforage.getItem<StoredLastPruneTimes>("lastPruneTimes"), ]); diff --git a/src/lib/Data/AniList/media.ts b/src/lib/Data/AniList/media.ts index 55263207..fee23113 100644 --- a/src/lib/Data/AniList/media.ts +++ b/src/lib/Data/AniList/media.ts @@ -212,7 +212,7 @@ interface CollectionOptions { const assignDefaultOptions = (options: CollectionOptions) => { const nonNullOptions: CollectionOptions = { - includeCompleted: false, + includeCompleted: true, forcePrune: false, all: false, addNotification: undefined, @@ -250,17 +250,36 @@ const collectionKey = ( includeRelations: options.includeRelations, }); -const cacheStorageKey = (type: Type) => - type === Type.Anime ? "anime" : "manga"; +const usesSharedMediaStore = (options: CollectionOptions) => + !!options.includeCompleted && !options.all && !options.includeRelations; + +const cacheStorageKey = (type: Type, options: CollectionOptions) => { + const baseKey = type === Type.Anime ? "anime:v2" : "manga:v2"; + + if (usesSharedMediaStore(options)) return baseKey; + + return [ + baseKey, + options.includeCompleted ? "completed" : "default", + options.all ? "all" : "scoped", + options.includeRelations ? "relations" : "plain", + ].join(":"); +}; const hydrateCollectionInputs = async ( type: Type, + options: CollectionOptions, mediaCache: string | undefined, currentLastPruneAt: string | number, ) => { if (!browser) return { mediaCache, currentLastPruneAt }; - const shouldReadStoredCache = mediaCache === undefined || mediaCache === ""; + if (!usesSharedMediaStore(options)) mediaCache = ""; + + const shouldReadStoredCache = + !usesSharedMediaStore(options) || + mediaCache === undefined || + mediaCache === ""; const shouldReadStoredPruneTime = String(currentLastPruneAt) === "" || Number(currentLastPruneAt) <= 1; @@ -269,7 +288,7 @@ const hydrateCollectionInputs = async ( const [storedCache, storedPruneTimes] = await Promise.all([ shouldReadStoredCache - ? localforage.getItem<string>(cacheStorageKey(type)) + ? localforage.getItem<string>(cacheStorageKey(type, options)) : Promise.resolve(null), shouldReadStoredPruneTime ? localforage.getItem<{ @@ -310,6 +329,7 @@ export const mediaListCollection = async ( const currentCacheMinutes = settings.get().cacheMinutes; const hydratedInputs = await hydrateCollectionInputs( type, + options, mediaCache, currentLastPruneAt, ); @@ -329,10 +349,12 @@ export const mediaListCollection = async ( ) { if (type === Type.Anime) { lastPruneTimes.setKey("anime", new Date().getTime()); - anime.set(""); + + if (usesSharedMediaStore(options)) anime.set(""); } else { lastPruneTimes.setKey("manga", new Date().getTime()); - manga.set(""); + + if (usesSharedMediaStore(options)) manga.set(""); } mediaCache = ""; @@ -374,9 +396,15 @@ export const mediaListCollection = async ( options.all, ); - if (mediaCache === "") - if (type === Type.Anime) anime.set(JSON.stringify(flattened)); - else manga.set(JSON.stringify(flattened)); + if (mediaCache === "") { + const serialized = JSON.stringify(flattened); + + if (usesSharedMediaStore(options)) { + if (type === Type.Anime) anime.set(serialized); + else manga.set(serialized); + } else if (browser) + await localforage.setItem(cacheStorageKey(type, options), serialized); + } if (options.addNotification) options.addNotification( diff --git a/src/lib/List/Anime/CleanAnimeList.svelte b/src/lib/List/Anime/CleanAnimeList.svelte index 06c5d398..4bc55772 100644 --- a/src/lib/List/Anime/CleanAnimeList.svelte +++ b/src/lib/List/Anime/CleanAnimeList.svelte @@ -62,14 +62,7 @@ let totalEpisodeDueCount = media ); }) .reduce((a, b) => a + b, 0); -const lists = Array.from( - new Set( - media - .flatMap((m) => Object.entries(m.mediaListEntry?.customLists ?? {})) - .filter(([_key, value]) => value) - .map(([key]) => key), - ), -); +let lists: string[] = []; let filterKind = upcoming ? "Upcoming" : notYetReleased @@ -83,6 +76,15 @@ $: selectedList = disableFilter ? "All" : ($stateBin[filterKey] as string) || "All"; +$: lists = Array.from( + new Set( + media + .flatMap((m) => Object.entries(m.mediaListEntry?.customLists ?? {})) + .filter(([_key, value]) => value) + .map(([key]) => key), + ), +); + $: filteredMedia = selectedList === "All" || !$settings.displayMediaListFilter ? media diff --git a/src/lib/List/Anime/CompletedAnimeList.svelte b/src/lib/List/Anime/CompletedAnimeList.svelte index 9c58a311..ec9955b3 100644 --- a/src/lib/List/Anime/CompletedAnimeList.svelte +++ b/src/lib/List/Anime/CompletedAnimeList.svelte @@ -74,6 +74,7 @@ onMount(async () => { $anime, $lastPruneTimes.anime, { + includeCompleted: true, addNotification, }, ); diff --git a/src/lib/List/Manga/CleanMangaList.svelte b/src/lib/List/Manga/CleanMangaList.svelte index cacc7006..db5778da 100644 --- a/src/lib/List/Manga/CleanMangaList.svelte +++ b/src/lib/List/Manga/CleanMangaList.svelte @@ -47,7 +47,15 @@ let totalEpisodeDueCount = media return (manga.episodes || 1) - (manga.mediaListEntry?.progress || 0); }) .reduce((a, b) => a + b, 0); -const lists = Array.from( +let lists: string[] = []; +const filterKind = due ? "due" : "completed"; +const filterKey = `${filterKind}MangaListFilter`; + +$: selectedList = disableFilter + ? "All" + : ($stateBin[filterKey] as string) || "All"; + +$: lists = Array.from( new Set( media .flatMap((m) => Object.entries(m.mediaListEntry?.customLists ?? {})) @@ -55,12 +63,6 @@ const lists = Array.from( .map(([key]) => key), ), ); -const filterKind = due ? "due" : "completed"; -const filterKey = `${filterKind}MangaListFilter`; - -$: selectedList = disableFilter - ? "All" - : ($stateBin[filterKey] as string) || "All"; $: filteredMedia = selectedList === "All" || !$settings.displayMediaListFilter |