From bdad50666b3ff874c9b84fd83ef0dbd993b20f86 Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Mon, 7 Jul 2025 23:50:15 +0600 Subject: [PATCH] fix: wait for to finish quiz --- src/components/AIQuiz/AIMCQQuestion.tsx | 25 ++++++++++++++++--- src/components/AIQuiz/AIOpenEndedQuestion.tsx | 17 +++++++++++-- src/components/AIQuiz/AIQuizContent.tsx | 13 +++++++--- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/components/AIQuiz/AIMCQQuestion.tsx b/src/components/AIQuiz/AIMCQQuestion.tsx index a4819e026..9ce07461b 100644 --- a/src/components/AIQuiz/AIMCQQuestion.tsx +++ b/src/components/AIQuiz/AIMCQQuestion.tsx @@ -14,11 +14,20 @@ type AIMCQQuestionProps = { setSelectedOptions: (options: number[]) => void; onSubmit: (status: QuestionState['status']) => void; onNext: () => void; + isLastQuestion: boolean; + onComplete: () => void; }; export function AIMCQQuestion(props: AIMCQQuestionProps) { - const { question, questionState, setSelectedOptions, onSubmit, onNext } = - props; + const { + question, + questionState, + setSelectedOptions, + onSubmit, + onNext, + isLastQuestion, + onComplete, + } = props; const { title: questionText, options, answerExplanation } = question; const { isSubmitted, selectedOptions = [] } = questionState; @@ -45,7 +54,11 @@ export function AIMCQQuestion(props: AIMCQQuestionProps) { const handleSubmit = () => { if (isSubmitted) { - onNext?.(); + if (isLastQuestion) { + onComplete(); + } else { + onNext(); + } return; } @@ -143,7 +156,11 @@ export function AIMCQQuestion(props: AIMCQQuestionProps) { onClick={handleSubmit} disabled={!canSubmit} > - {isSubmitted ? 'Next Question' : 'Submit Answer'} + {isSubmitted + ? isLastQuestion + ? 'Finish Quiz' + : 'Next Question' + : 'Submit Answer'} ); diff --git a/src/components/AIQuiz/AIOpenEndedQuestion.tsx b/src/components/AIQuiz/AIOpenEndedQuestion.tsx index 293d734a9..c3d797e71 100644 --- a/src/components/AIQuiz/AIOpenEndedQuestion.tsx +++ b/src/components/AIQuiz/AIOpenEndedQuestion.tsx @@ -20,6 +20,9 @@ type AIOpenEndedQuestionProps = { setUserAnswer: (answer: string) => void; setCorrectAnswer: (answer: string) => void; + + isLastQuestion: boolean; + onComplete: () => void; }; export function AIOpenEndedQuestion(props: AIOpenEndedQuestionProps) { @@ -31,6 +34,8 @@ export function AIOpenEndedQuestion(props: AIOpenEndedQuestionProps) { onNext, setUserAnswer, setCorrectAnswer, + isLastQuestion, + onComplete, } = props; const { title: questionText } = question; @@ -63,7 +68,11 @@ export function AIOpenEndedQuestion(props: AIOpenEndedQuestionProps) { const handleSubmit = async () => { if (isSubmitted) { - onNext?.(); + if (isLastQuestion) { + onComplete(); + } else { + onNext(); + } return; } @@ -126,7 +135,11 @@ export function AIOpenEndedQuestion(props: AIOpenEndedQuestionProps) { {isVerifying ? ( ) : isSubmitted ? ( - 'Next Question' + isLastQuestion ? ( + 'Finish Quiz' + ) : ( + 'Next Question' + ) ) : ( 'Submit Answer' )} diff --git a/src/components/AIQuiz/AIQuizContent.tsx b/src/components/AIQuiz/AIQuizContent.tsx index 34a691117..d745198c1 100644 --- a/src/components/AIQuiz/AIQuizContent.tsx +++ b/src/components/AIQuiz/AIQuizContent.tsx @@ -46,6 +46,7 @@ export function AIQuizContent(props: AIQuizContentProps) { const activeQuestionState = questionStates[activeQuestionIndex] ?? DEFAULT_QUESTION_STATE; + const isLastQuestion = activeQuestionIndex === questions.length - 1; const handleSubmit = (status: QuestionState['status']) => { setQuestionStates((prev) => { @@ -62,10 +63,6 @@ export function AIQuizContent(props: AIQuizContentProps) { return newSelectedOptions; }); - - setQuizStatus( - activeQuestionIndex === questions.length - 1 ? 'submitted' : 'answering', - ); }; const handleSetUserAnswer = (userAnswer: string) => { @@ -147,6 +144,10 @@ export function AIQuizContent(props: AIQuizContentProps) { setActiveQuestionIndex(activeQuestionIndex + 1); }; + const handleComplete = () => { + setQuizStatus('submitted'); + }; + return (
@@ -192,6 +193,8 @@ export function AIQuizContent(props: AIQuizContentProps) { setSelectedOptions={handleSelectOptions} onSubmit={handleSubmit} onNext={handleNextQuestion} + isLastQuestion={isLastQuestion} + onComplete={handleComplete} /> )} @@ -205,6 +208,8 @@ export function AIQuizContent(props: AIQuizContentProps) { onNext={handleNextQuestion} setUserAnswer={handleSetUserAnswer} setCorrectAnswer={handleSetCorrectAnswer} + isLastQuestion={isLastQuestion} + onComplete={handleComplete} /> )}