From fe9a191a008b2f5e4d8fece1b36d6bd3b1f068f2 Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Wed, 6 Sep 2023 03:54:07 -0700
Subject: fix(activity): last activity check

---
 src/routes/+layout.svelte | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

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

diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index a11ea3ee..15073db3 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -28,9 +28,32 @@
 			currentUserIdentity = JSON.parse($userIdentity);
 			currentUserIdentity.name = currentUserIdentity.name;
 			lastActivityWasToday =
-				(await lastActivityDate(currentUserIdentity)).toDateString() === new Date().toDateString();
+				(await lastActivityDate(currentUserIdentity)).toDateString() >= new Date().toDateString();
 		}
 	});
+
+	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>
 
 <p />
@@ -49,7 +72,10 @@
 {#if !lastActivityWasToday}
 	<p />
 
-	<p>You don't have any new activity statuses from the past day! Create one to keep your streak!</p>
+	<p>
+		You don't have any new activity statuses from the past day! Create one within {timeLeftToday()}
+		to keep your streak!
+	</p>
 {/if}
 
 <p />
-- 
cgit v1.2.3

