From bc986fb6efa925b2ef1e566ce20fa0aa4655f6aa Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Tue, 3 Oct 2023 14:43:05 -0700
Subject: feat(manga): no load on increment

---
 src/lib/List/Template/MangaListTemplate.svelte | 57 ++++++++++----------------
 1 file changed, 21 insertions(+), 36 deletions(-)

(limited to 'src/lib/List/Template/MangaListTemplate.svelte')

diff --git a/src/lib/List/Template/MangaListTemplate.svelte b/src/lib/List/Template/MangaListTemplate.svelte
index 9bbfec49..904d14cf 100644
--- a/src/lib/List/Template/MangaListTemplate.svelte
+++ b/src/lib/List/Template/MangaListTemplate.svelte
@@ -9,6 +9,7 @@
 	import lastPruneTimes from '../../../stores/lastPruneTimes';
 	import ListTitle from '../ListTitle.svelte';
 	import Error from '$lib/Error.svelte';
+	import CleanMangaList from '../CleanMangaList.svelte';
 
 	export let user: AniListAuthorisation;
 	export let identity: UserIdentity;
@@ -19,6 +20,7 @@
 	let startTime: number;
 	let endTime: number;
 	let lastUpdatedMedia = -1;
+	let previousMangaList: Media[] = [];
 
 	const keyCacher = setInterval(() => {
 		startTime = performance.now();
@@ -102,9 +104,10 @@
 		return finalMedia;
 	};
 
-	const updateMedia = async (id: number, progress: number | undefined) => {
+	const updateMedia = async (id: number, progress: number | undefined, media: Media[]) => {
 		await chapterDatabase.chapters.delete(id);
 		await fetch(`/api/anilist-increment?id=${id}&progress=${(progress || 0) + 1}`).then(() => {
+			previousMangaList = media;
 			mangaLists = mediaListCollection(
 				user,
 				identity,
@@ -134,44 +137,26 @@
 </script>
 
 {#await mangaLists}
-	<ListTitle />
-
-	<ul><li>Loading ...</li></ul>
+	<CleanMangaList
+		media={previousMangaList}
+		{cleanCache}
+		{endTime}
+		{lastUpdatedMedia}
+		{updateMedia}
+		disableIncrement
+	/>
 {:then media}
 	{#await cleanMedia(media, displayUnresolved)}
-		<ListTitle />
-
-		<ul><li>Loading ...</li></ul>
+		<CleanMangaList
+			media={previousMangaList}
+			{cleanCache}
+			{endTime}
+			{lastUpdatedMedia}
+			{updateMedia}
+			disableIncrement
+		/>
 	{:then cleanedMedia}
-		<ListTitle count={cleanedMedia.length} time={endTime / 1000}>
-			<a href={'#'} title="Force a refresh" on:click={cleanCache}>Force</a>
-		</ListTitle>
-
-		{#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>
-					<a href={`https://anilist.co/manga/${manga.id}`} target="_blank">
-						{#if lastUpdatedMedia === manga.id}
-							<span style="color: lightcoral">
-								{manga.title.english || manga.title.romaji || manga.title.native}
-							</span>
-						{:else}
-							{manga.title.english || manga.title.romaji || manga.title.native}
-						{/if}
-					</a>
-					<span style="opacity: 50%;">|</span>
-					{(manga.mediaListEntry || { progress: 0 }).progress}
-					<a href={'#'} on:click={() => updateMedia(manga.id, manga.mediaListEntry?.progress)}>+</a>
-					[{manga.episodes || '?'}]
-				</li>
-			{/each}
-		</ul>
+		<CleanMangaList media={cleanedMedia} {cleanCache} {endTime} {lastUpdatedMedia} {updateMedia} />
 	{:catch}
 		<ListTitle count={-1337} time={0} />
 
-- 
cgit v1.2.3

