From 19b51ab69176eb4f834c2c497f4c93a13779d7c7 Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Wed, 6 Sep 2023 00:30:46 -0700
Subject: feat(list): cache flattened

---
 src/lib/List/Due/MangaList.svelte | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

(limited to 'src/lib/List/Due/MangaList.svelte')

diff --git a/src/lib/List/Due/MangaList.svelte b/src/lib/List/Due/MangaList.svelte
index e7a1321f..379ec228 100644
--- a/src/lib/List/Due/MangaList.svelte
+++ b/src/lib/List/Due/MangaList.svelte
@@ -1,5 +1,5 @@
 <script lang="ts">
-	import { mediaListCollection, Type, flattenLists, type Media } from '$lib/AniList/media';
+	import { mediaListCollection, Type, type Media } from '$lib/AniList/media';
 	import type { UserIdentity, AniListAuthorisation } from '$lib/AniList/identity';
 	import { onDestroy, onMount } from 'svelte';
 	import { chapterCount } from '$lib/mangadex';
@@ -12,7 +12,7 @@
 	export let identity: UserIdentity;
 	export let displayUnresolved: boolean;
 
-	let mangaLists: Promise<{ entries: { media: Media }[] }[]>;
+	let mangaLists: Promise<Media[]>;
 	let startTime: number;
 	let endTime: number;
 
@@ -31,10 +31,7 @@
 		clearInterval(keyCacher);
 	});
 
-	const cleanMedia = async (
-		media: { entries: { media: Media }[] }[],
-		displayUnresolved: boolean
-	) => {
+	const cleanMedia = async (media: Media[], displayUnresolved: boolean) => {
 		if (media === undefined) {
 			return [];
 		}
@@ -54,8 +51,7 @@
 			}
 		}
 
-		const flattenedLists = flattenLists(media);
-		const releasingMedia = flattenedLists.filter(
+		const releasingMedia = media.filter(
 			(media: Media) =>
 				media.status == 'RELEASING' &&
 				media.format != 'NOVEL' &&
@@ -117,6 +113,17 @@
 			);
 		});
 	};
+
+	const cleanCache = () => {
+		mangaLists = mediaListCollection(
+			user,
+			identity,
+			Type.Manga,
+			$manga,
+			$lastPruneTimes.manga,
+			true
+		);
+	};
 </script>
 
 {#await mangaLists}
@@ -134,6 +141,12 @@
 			<small style="opacity: 50%">{endTime / 1000}s</small>
 		</summary>
 
+		{#if cleanedMedia.length === 0}
+			<ul>
+				<li>No manga to display. <a href={'#'} on:click={cleanCache}>Force refresh</a></li>
+			</ul>
+		{/if}
+
 		<ul>
 			{#each cleanedMedia as manga}
 				<li>
-- 
cgit v1.2.3

