diff --git a/components/HomeClient.tsx b/components/HomeClient.tsx index 1524c04..ac49f34 100644 --- a/components/HomeClient.tsx +++ b/components/HomeClient.tsx @@ -56,6 +56,7 @@ export default function Home({ sponsor }: HomeProps) { const [started, setStarted] = useState(false); const [feedbackOpen, setFeedbackOpen] = useState(false); const [statsOpen, setStatsOpen] = useState(false); + const [revealedSolutions, setRevealedSolutions] = useState>>({}); const [selectedPosition, setSelectedPosition] = useState("DEF"); const [stats, setStats] = useState(() => createInitialStats()); const [draft, setDraft] = useState>(() => getFixedGuess(dailyPuzzles[0])); @@ -65,6 +66,9 @@ export default function Home({ sponsor }: HomeProps) { const activeProgress = progress[activeDifficulty]; const isLocked = activeProgress.locked; const isFinished = activeProgress.solved || activeProgress.attempts.length >= MAX_ATTEMPTS; + const hasFailed = !activeProgress.solved && activeProgress.attempts.length >= MAX_ATTEMPTS; + const solutionRevealed = revealedSolutions[activeDifficulty] === true; + const pitchDraft = solutionRevealed ? activePuzzle.solution : draft; const t = useMemo(() => getDictionary(locale), [locale]); const quote = useMemo(() => quoteForDay(dateKey, locale), [dateKey, locale]); const globalStatsShareText = useMemo(() => buildGlobalStatsShareText(stats, t), [stats, t]); @@ -211,6 +215,18 @@ export default function Home({ sponsor }: HomeProps) { setMessage(t.hintRevealed(positionToReveal)); } + function revealSolution() { + if (!hasFailed) return; + + setRevealedSolutions((current) => ({ ...current, [activeDifficulty]: true })); + setDraft(activePuzzle.solution); + setMessage(t.solutionRevealed); + trackEvent("solution_revealed", { + difficulty: activeDifficulty, + puzzle_number: getPuzzleNumber(dateKey), + }); + } + function changeLocale(nextLocale: Locale) { setLocale(nextLocale); window.localStorage.setItem("hidden11-locale", nextLocale); @@ -239,6 +255,15 @@ export default function Home({ sponsor }: HomeProps) { const actionButtons = (
+ {hasFailed && !solutionRevealed ? ( + + ) : null}