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/WatchingAnimeList.svelte | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

(limited to 'src/lib/List/WatchingAnimeList.svelte')

diff --git a/src/lib/List/WatchingAnimeList.svelte b/src/lib/List/WatchingAnimeList.svelte
index 52e3c505..fc8909c1 100644
--- a/src/lib/List/WatchingAnimeList.svelte
+++ b/src/lib/List/WatchingAnimeList.svelte
@@ -1,7 +1,7 @@
 <script lang="ts">
 	/* eslint svelte/no-at-html-tags: "off" */
 
-	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 { onMount } from 'svelte';
 	import anime from '../../stores/anime';
@@ -11,7 +11,7 @@
 	export let user: AniListAuthorisation;
 	export let identity: UserIdentity;
 
-	let animeLists: Promise<{ entries: { media: Media }[] }[]>;
+	let animeLists: Promise<Media[]>;
 	let startTime: number;
 	let endTime: number;
 
@@ -20,13 +20,12 @@
 		animeLists = mediaListCollection(user, identity, Type.Anime, $anime, $lastPruneTimes.anime);
 	});
 
-	const cleanMedia = (media: { entries: { media: Media }[] }[]) => {
+	const cleanMedia = (media: Media[]) => {
 		if (media === undefined) {
 			return [];
 		}
 
-		const flattenedLists = flattenLists(media);
-		const releasingMedia = flattenedLists.filter(
+		const releasingMedia = media.filter(
 			(media: Media) =>
 				media.status !== 'RELEASING' &&
 				media.status !== 'NOT_YET_RELEASED' &&
@@ -81,6 +80,17 @@
 			);
 		});
 	};
+
+	const cleanCache = () => {
+		animeLists = mediaListCollection(
+			user,
+			identity,
+			Type.Anime,
+			$anime,
+			$lastPruneTimes.anime,
+			true
+		);
+	};
 </script>
 
 {#await animeLists}
@@ -95,6 +105,12 @@
 		<small style="opacity: 50%">{endTime / 1000}s</small></summary
 	>
 
+	{#if cleanedMedia.length === 0}
+		<ul>
+			<li>No anime to display. <a href={'#'} on:click={cleanCache}>Force refresh</a></li>
+		</ul>
+	{/if}
+
 	<ul>
 		{#each cleanedMedia as anime}
 			<li>
-- 
cgit v1.2.3

