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

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

diff --git a/src/lib/List/Due/AnimeList.svelte b/src/lib/List/Due/AnimeList.svelte
index 5024f8c2..83511ca0 100644
--- a/src/lib/List/Due/AnimeList.svelte
+++ b/src/lib/List/Due/AnimeList.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 { onDestroy, onMount } from 'svelte';
 	import anime from '../../../stores/anime';
@@ -12,7 +12,7 @@
 	export let identity: UserIdentity;
 	export let displayUnresolved: boolean;
 
-	let animeLists: Promise<{ entries: { media: Media }[] }[]>;
+	let animeLists: Promise<Media[]>;
 	let startTime: number;
 	let endTime: number;
 
@@ -38,13 +38,12 @@
 		clearInterval(keyCacher);
 	});
 
-	const cleanMedia = (media: { entries: { media: Media }[] }[], displayUnresolved: boolean) => {
+	const cleanMedia = (media: Media[], displayUnresolved: boolean) => {
 		if (media === undefined) {
 			return [];
 		}
 
-		const flattenedLists = flattenLists(media);
-		const releasingMedia = flattenedLists.filter(
+		const releasingMedia = media.filter(
 			(media: Media) =>
 				media.status == 'RELEASING' &&
 				(media.mediaListEntry || { status: 'DROPPED' }).status !=
@@ -152,6 +151,17 @@
 			);
 		});
 	};
+
+	const cleanCache = () => {
+		animeLists = mediaListCollection(
+			user,
+			identity,
+			Type.Anime,
+			$anime,
+			$lastPruneTimes.anime,
+			true
+		);
+	};
 </script>
 
 {#await animeLists}
@@ -166,6 +176,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

