From 0aee4b6514162aa34d0f8b4982273fb4adf2b349 Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Wed, 13 Dec 2023 04:26:46 -0800
Subject: feat(anime): update airing time

---
 src/lib/List/Anime/CleanAnimeList.svelte | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

(limited to 'src/lib/List/Anime/CleanAnimeList.svelte')

diff --git a/src/lib/List/Anime/CleanAnimeList.svelte b/src/lib/List/Anime/CleanAnimeList.svelte
index e082f00a..0a49b7c0 100644
--- a/src/lib/List/Anime/CleanAnimeList.svelte
+++ b/src/lib/List/Anime/CleanAnimeList.svelte
@@ -8,6 +8,7 @@
 	import ListTitle from '../ListTitle.svelte';
 	import MediaTitle from '../MediaTitleDisplay.svelte';
 	import { outboundLink } from '$lib/Media/media';
+	import { onDestroy } from 'svelte';
 
 	export let media: Media[];
 	export let title: string;
@@ -19,6 +20,23 @@
 	export let completed = false;
 	export let previousAnimeList: Media[];
 	export let pendingUpdate: number | null;
+
+	const keyCacher = setInterval(
+		() => (media = media),
+		(() => {
+			const airingAt = media.find((m) => m.nextAiringEpisode?.airingAt)?.nextAiringEpisode
+				?.airingAt;
+			const untilAiring = airingAt
+				? Math.round((airingAt - Date.now() / 1000) * 100) / 100
+				: undefined;
+
+			if (untilAiring && untilAiring < 3600) return 10000;
+
+			return 300000;
+		})()
+	);
+
+	onDestroy(() => clearInterval(keyCacher));
 </script>
 
 <ListTitle time={endTime / 1000} count={media.length} custom={title} />
-- 
cgit v1.2.3

