From 67c392e288c9876e9542b7724f4f84d4c4dcd61a Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Tue, 2 Jan 2024 02:22:58 -0800
Subject: refactor(lastactivity): move info to component

---
 src/routes/+page.svelte | 46 ++--------------------------------------------
 1 file changed, 2 insertions(+), 44 deletions(-)

(limited to 'src/routes/+page.svelte')

diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte
index ec553c66..2809a649 100644
--- a/src/routes/+page.svelte
+++ b/src/routes/+page.svelte
@@ -6,14 +6,13 @@
 	import UpcomingAnimeList from '$lib/List/Anime/UpcomingAnimeList.svelte';
 	import userIdentity from '$stores/userIdentity';
 	import settings from '$stores/settings';
-	import { lastActivityDate } from '$lib/AniList/activity';
 	import ListTitle from '$lib/List/ListTitle.svelte';
 	import HeadTitle from '$lib/HeadTitle.svelte';
+	import LastActivity from '$lib/LastActivity.svelte';
 
 	export let data;
 
 	let currentUserIdentity = { name: '', id: -1 };
-	let lastActivityWasToday = true;
 
 	onMount(async () => {
 		if ($settings.displayLimitListHeight) {
@@ -31,54 +30,13 @@
 
 			currentUserIdentity = JSON.parse($userIdentity);
 			currentUserIdentity.name = currentUserIdentity.name;
-			lastActivityWasToday =
-				(await lastActivityDate(currentUserIdentity, data.user)).date.toDateString() >=
-				new Date().toDateString();
-
-			if (!lastActivityWasToday) {
-				if ($settings.displayLimitListHeight) {
-					document.querySelectorAll('.list').forEach((list) => {
-						(list as HTMLElement).style.maxHeight = `calc((100vh - ${
-							document.querySelector('#list-container')?.getBoundingClientRect().top
-						}px) - 5rem)`;
-					});
-				}
-			}
 		}
 	});
-
-	const timeLeftToday = () => {
-		const now = new Date();
-		const currentHour = now.getHours();
-		const currentMinute = now.getMinutes();
-		const hoursLeft = 24 - currentHour;
-		let minutesLeft = 0;
-		let timeLeft = '';
-
-		if (hoursLeft > 0) {
-			minutesLeft = hoursLeft * 60 - currentMinute;
-		} else {
-			minutesLeft = 24 * 60 - (currentHour * 60 + currentMinute);
-		}
-
-		if (minutesLeft > 60) {
-			timeLeft = `${Math.round(minutesLeft / 60)} hours`;
-		} else {
-			timeLeft = `${minutesLeft} minutes`;
-		}
-
-		return timeLeft;
-	};
 </script>
 
 <HeadTitle />
 
-{#if !lastActivityWasToday}
-	<p>
-		You don't have any new activity statuses from the past day! Create one within {timeLeftToday()}
-		to keep your streak!
-	</p>
-{/if}
+<LastActivity user={data.user} />
 
 <div
 	id="list-container"
-- 
cgit v1.2.3

