Update QuizRunner to accept and use autoStart prop
This commit is contained in:
@@ -10,6 +10,7 @@ const TOTAL_QUESTIONS = 10;
|
||||
interface QuizRunnerProps {
|
||||
defaultMode?: Mode;
|
||||
defaultEntryId?: string;
|
||||
autoStart?: boolean;
|
||||
}
|
||||
|
||||
interface TargetHit {
|
||||
@@ -194,7 +195,7 @@ function ExplanationPanel({ question, targets }: { question: QuizQuestionWithEnt
|
||||
);
|
||||
}
|
||||
|
||||
export default function QuizRunner({ defaultMode = 'all', defaultEntryId }: QuizRunnerProps) {
|
||||
export default function QuizRunner({ defaultMode = 'all', defaultEntryId, autoStart }: QuizRunnerProps) {
|
||||
const [entries, setEntries] = useState<EntrySummary[]>([]);
|
||||
const [loadingEntries, setLoadingEntries] = useState(true);
|
||||
const [mode, setMode] = useState<Mode>(defaultMode);
|
||||
@@ -223,6 +224,13 @@ export default function QuizRunner({ defaultMode = 'all', defaultEntryId }: Quiz
|
||||
}
|
||||
}, [defaultEntryId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (autoStart && defaultEntryId && entries.length > 0) {
|
||||
startQuiz();
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [autoStart, defaultEntryId, entries.length]);
|
||||
|
||||
const currentQuestion = useMemo(() => questions[currentIndex], [questions, currentIndex]);
|
||||
|
||||
const resetQuestionState = () => {
|
||||
|
||||
Reference in New Issue
Block a user