diff options
| author | Pinapelz <yukais@pinapelz.com> | 2026-06-03 17:50:38 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2026-06-03 17:50:38 -0700 |
| commit | 7260fb0a48c3486e507f79e736b4edf71445f4e7 (patch) | |
| tree | a6d6c8efbba0e864aa09d033fb761c8e661fb758 | |
| parent | 14172f9dd64ce91ba5cf51f82c53deb6a81d68a6 (diff) | |
show error if daily is not generated yet
| -rw-r--r-- | src/components/Game/index.tsx | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/components/Game/index.tsx b/src/components/Game/index.tsx index 9024b03..3b45329 100644 --- a/src/components/Game/index.tsx +++ b/src/components/Game/index.tsx @@ -20,6 +20,18 @@ interface Props { onPlayAgain?: () => void; } +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, @@ -31,7 +43,26 @@ export function Game({ mode = "daily", onPlayAgain, }: Props) { - if (didGuess || currentTry === 6) { + const [sessionDate] = React.useState(() => getUtcDate()); + const isGameOver = didGuess || currentTry === 6; + const recentFinishedPlay = localStorage.getItem("recentFinishedPlay"); + const isBlocked = + mode === "daily" && + !!recentFinishedPlay && + new Date(sessionDate) > new Date(recentFinishedPlay) && + !checkDailyIsGenerated(); + + React.useEffect(() => { + if (!isGameOver) return; + + localStorage.setItem("recentFinishedPlay", sessionDate); + }, [isGameOver, sessionDate]); + + if (isBlocked) { + return <h1>Daily MIXX is not available yet. Check back soon!</h1>; + } + + if (isGameOver) { return ( <Result didGuess={didGuess} @@ -43,6 +74,7 @@ export function Game({ /> ); } + return ( <> {guesses.map((guess: GuessType, index) => ( @@ -55,7 +87,6 @@ export function Game({ )} <Search currentTry={currentTry} setSelectedSong={setSelectedSong} /> - <Styled.Buttons> <Button onClick={skip}> {currentTry === 5 |
