mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-09-09 08:40:40 +02:00
fix: wait for to finish quiz
This commit is contained in:
@@ -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'}
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
|
@@ -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 ? (
|
||||
<Loader2Icon className="size-4 animate-spin stroke-[2.5]" />
|
||||
) : isSubmitted ? (
|
||||
'Next Question'
|
||||
isLastQuestion ? (
|
||||
'Finish Quiz'
|
||||
) : (
|
||||
'Next Question'
|
||||
)
|
||||
) : (
|
||||
'Submit Answer'
|
||||
)}
|
||||
|
@@ -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 (
|
||||
<div className="flex h-full w-full flex-col">
|
||||
<div className="relative flex h-full flex-col overflow-y-auto">
|
||||
@@ -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}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
|
Reference in New Issue
Block a user