From e780de5b40b2736119c5303ab30397a7c88965a6 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Thu, 8 Jan 2026 02:06:05 +0100 Subject: [PATCH] Add effects to manage question state and history in QuizRunner --- client/src/components/QuizRunner.tsx | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/client/src/components/QuizRunner.tsx b/client/src/components/QuizRunner.tsx index 0218346..453af15 100644 --- a/client/src/components/QuizRunner.tsx +++ b/client/src/components/QuizRunner.tsx @@ -373,6 +373,32 @@ export default function QuizRunner({ defaultMode = 'all', defaultEntryId, autoSt } }; + useEffect(() => { + if (status !== 'running') return; + const saved = history[currentIndex]; + if (saved) { + setResponse(saved.response); + setShowResult(true); + setLastCorrect(saved.correct); + setLastSkipped(saved.skipped); + setShowExplanation(saved.showExplanation); + } else { + resetQuestionState(); + } + }, [currentIndex, history, status]); + + useEffect(() => { + if (!showResult) return; + setHistory((prev) => { + const next = [...prev]; + const existing = next[currentIndex]; + if (existing) { + next[currentIndex] = { ...existing, showExplanation }; + } + return next; + }); + }, [showExplanation, showResult, currentIndex]); + if (loadingEntries) { return
Loading quiz setup…
; }