From 95602704d53bb72d96d4947869bce63830888d52 Mon Sep 17 00:00:00 2001
From: Pinapelz <yukais@pinapelz.com>
Date: Thu, 4 Jun 2026 18:34:18 -0700
Subject: overhaul how daily is updated from server to client

---
 src/components/Game/index.tsx | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

(limited to 'src/components/Game/index.tsx')

diff --git a/src/components/Game/index.tsx b/src/components/Game/index.tsx
index cde682d..59f9289 100644
--- a/src/components/Game/index.tsx
+++ b/src/components/Game/index.tsx
@@ -11,6 +11,7 @@ import * as Styled from "./index.styled";
 interface Props {
   guesses: GuessType[];
   todaysSolution: Song;
+  dailyDate?: string;
   currentTry: number;
   didGuess: boolean;
   setSelectedSong: React.Dispatch<React.SetStateAction<Song | undefined>>;
@@ -24,17 +25,10 @@ function getUtcDate() {
   return new Date().toISOString().split("T")[0];
 }
 
-function checkDailyIsGenerated(): boolean {
-  const CDN_URL = import.meta.env.VITE_CDN_URL;
-  if (!CDN_URL) return false;
-
-  const date = getUtcDate();
-  return !!localStorage.getItem(`${CDN_URL}/${date}.mp3`);
-}
-
 export function Game({
   guesses,
   todaysSolution,
+  dailyDate,
   currentTry,
   didGuess,
   setSelectedSong,
@@ -43,22 +37,23 @@ export function Game({
   mode = "daily",
   onPlayAgain,
 }: Props) {
-  const [sessionDate] = React.useState(() => getUtcDate());
   const recentFinishedPlay = localStorage.getItem("recentFinishedPlay");
   const hasFinishedCurrentRound = didGuess || currentTry >= guesses.length;
-  const isGameOver = hasFinishedCurrentRound;
+  const hasFinishedResponseDaily =
+    mode === "daily" && !!dailyDate && recentFinishedPlay === dailyDate;
+  const isGameOver = hasFinishedCurrentRound || hasFinishedResponseDaily;
   const isBlocked =
     mode === "daily" &&
-    !!recentFinishedPlay &&
-    new Date(sessionDate) > new Date(recentFinishedPlay) &&
-    !checkDailyIsGenerated();
+    !!dailyDate &&
+    !hasFinishedResponseDaily &&
+    new Date(getUtcDate()) > new Date(dailyDate);
 
   React.useEffect(() => {
     if (mode !== "daily") return;
     if (!hasFinishedCurrentRound) return;
 
-    localStorage.setItem("recentFinishedPlay", sessionDate);
-  }, [mode, hasFinishedCurrentRound, sessionDate]);
+    localStorage.setItem("recentFinishedPlay", dailyDate ?? getUtcDate());
+  }, [mode, hasFinishedCurrentRound, dailyDate]);
 
   if (isBlocked) {
     return <h1>Daily MIXX is not available yet. Check back soon!</h1>;
-- 
cgit v1.2.3

