From c81e430c62459255fe02a75d3794860acd02c3b8 Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Sun, 10 Sep 2023 02:15:56 -0700
Subject: refactor(anime): generalise update media

---
 src/lib/List/Due/AnimeList.svelte | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 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 66a26712..b6d6f9ef 100644
--- a/src/lib/List/Due/AnimeList.svelte
+++ b/src/lib/List/Due/AnimeList.svelte
@@ -7,7 +7,7 @@
 	import anime from '../../../stores/anime';
 	import settings from '../../../stores/settings';
 	import lastPruneTimes from '../../../stores/lastPruneTimes';
-	import { airingTime, cleanCache, totalEpisodes } from '$lib/anime';
+	import { airingTime, cleanCache, totalEpisodes, updateMedia } from '$lib/anime';
 
 	export let user: AniListAuthorisation;
 	export let identity: UserIdentity;
@@ -104,12 +104,6 @@
 
 		return finalMedia;
 	};
-
-	const updateMedia = async (id: number, progress: number | undefined) => {
-		fetch(`/anilist/increment?id=${id}&progress=${(progress || 0) + 1}`).then(() => {
-			animeLists = cleanCache(user, identity);
-		});
-	};
 </script>
 
 {#await animeLists}
@@ -150,7 +144,15 @@
 				</a>
 				<span style="opacity: 50%;">|</span>
 				{(anime.mediaListEntry || { progress: 0 }).progress}{@html totalEpisodes(anime)}
-				<a href={'#'} on:click={() => updateMedia(anime.id, anime.mediaListEntry?.progress)}>+</a>
+				<a
+					href={'#'}
+					on:click={() =>
+						updateMedia(
+							anime.id,
+							anime.mediaListEntry?.progress,
+							() => (animeLists = cleanCache(user, identity))
+						)}>+</a
+				>
 				[{anime.nextAiringEpisode?.episode === -1
 					? '?'
 					: (anime.nextAiringEpisode?.episode || 1) - 1}]
-- 
cgit v1.2.3

