diff options
| author | Pinapelz <yukais@pinapelz.com> | 2026-06-05 22:08:51 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2026-06-05 22:08:51 -0700 |
| commit | cfc9cd8c7770ddc8f151610acd177e54169e28d7 (patch) | |
| tree | fcdc6d1b06966bef5198320ccd42e5a2aa1eea48 /src/components/Game/index.tsx | |
| parent | 16d92646308a65224784a9a9fdccd6f69d02955e (diff) | |
feat: historical stats tracking, chart
Diffstat (limited to 'src/components/Game/index.tsx')
| -rw-r--r-- | src/components/Game/index.tsx | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/components/Game/index.tsx b/src/components/Game/index.tsx index 59f9289..657b2af 100644 --- a/src/components/Game/index.tsx +++ b/src/components/Game/index.tsx @@ -47,13 +47,36 @@ export function Game({ !!dailyDate && !hasFinishedResponseDaily && new Date(getUtcDate()) > new Date(dailyDate); + const sessionDate = dailyDate ?? getUtcDate(); React.useEffect(() => { if (mode !== "daily") return; if (!hasFinishedCurrentRound) return; + localStorage.setItem("recentFinishedPlay", sessionDate); - localStorage.setItem("recentFinishedPlay", dailyDate ?? getUtcDate()); - }, [mode, hasFinishedCurrentRound, dailyDate]); + const historicalPlayData = localStorage.getItem("historicalPlayData"); + if (historicalPlayData === null) { + localStorage.setItem( + "historicalPlayData", + JSON.stringify({ + sessionDates: [sessionDate], + guesses: [currentTry], + didGuess: [didGuess], + }) + ); + } else { + const parsedData = JSON.parse(historicalPlayData); + if (parsedData.sessionDates.includes(sessionDate)) return; + localStorage.setItem( + "historicalPlayData", + JSON.stringify({ + sessionDates: [...parsedData.sessionDates, sessionDate], + guesses: [...parsedData.guesses, currentTry], + didGuess: [...parsedData.didGuess, didGuess], + }) + ); + } + }, [mode, hasFinishedCurrentRound, sessionDate, currentTry, didGuess]); if (isBlocked) { return <h1>Daily MIXX is not available yet. Check back soon!</h1>; @@ -67,6 +90,7 @@ export function Game({ todaysSolution={todaysSolution} guesses={guesses} mode={mode} + sessionDate={sessionDate} onPlayAgain={onPlayAgain} /> ); |
