From 6dcdb21d775e91e78c1ad06b15a9de206d91c05d Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Wed, 4 Oct 2023 17:54:20 -0700
Subject: feat(manga): instantly reactive increment

---
 src/lib/List/Template/MangaListTemplate.svelte | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

(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 75d12aa5..57f3998d 100644
--- a/src/lib/List/Template/MangaListTemplate.svelte
+++ b/src/lib/List/Template/MangaListTemplate.svelte
@@ -21,6 +21,7 @@
 	let endTime: number;
 	let lastUpdatedMedia = -1;
 	let previousMangaList: Media[];
+	let pendingUpdate = false;
 
 	const keyCacher = setInterval(() => {
 		startTime = performance.now();
@@ -105,6 +106,8 @@
 	};
 
 	const updateMedia = async (id: number, progress: number | undefined, media: Media[]) => {
+		pendingUpdate = true;
+
 		await chapterDatabase.chapters.delete(id);
 		await fetch(`/api/anilist-increment?id=${id}&progress=${(progress || 0) + 1}`).then(() => {
 			previousMangaList = media;
@@ -117,6 +120,7 @@
 				true
 			);
 			lastUpdatedMedia = id;
+			pendingUpdate = false;
 		});
 	};
 
@@ -145,6 +149,7 @@
 			{lastUpdatedMedia}
 			{updateMedia}
 			disableIncrement
+			{pendingUpdate}
 		/>
 	{:else}
 		<ListTitle />
@@ -161,6 +166,7 @@
 				{lastUpdatedMedia}
 				{updateMedia}
 				disableIncrement
+				{pendingUpdate}
 			/>
 		{:else}
 			<ListTitle />
@@ -168,7 +174,14 @@
 			<ul><li>Loading ...</li></ul>
 		{/if}
 	{:then cleanedMedia}
-		<CleanMangaList media={cleanedMedia} {cleanCache} {endTime} {lastUpdatedMedia} {updateMedia} />
+		<CleanMangaList
+			media={cleanedMedia}
+			{cleanCache}
+			{endTime}
+			{lastUpdatedMedia}
+			{updateMedia}
+			{pendingUpdate}
+		/>
 	{:catch}
 		<ListTitle count={-1337} time={0} />
 
-- 
cgit v1.2.3

