From 3807eee07b3486ad1b6dd7250206499660899836 Mon Sep 17 00:00:00 2001 From: andrewtan2000 Date: Sun, 29 Sep 2024 15:02:05 +0800 Subject: [PATCH] Revert "Question Length" This reverts commit 47236f5573d87979d61140a3ec982b4c5350389f. --- app/(main)/quiz/page.tsx | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/app/(main)/quiz/page.tsx b/app/(main)/quiz/page.tsx index face4c7..27639be 100644 --- a/app/(main)/quiz/page.tsx +++ b/app/(main)/quiz/page.tsx @@ -151,7 +151,7 @@ const QuizPage: React.FC = () => { const handleNextQuestion = () => { if (currentQuestionLength > 0) { - if (currentQuestionIndex < (currentQuestionLength || 0) - 1) { + if (currentQuestionIndex < currentQuestionLength - 1) { setExplanationsVisible({}); setIsAnswerSubmitted(false); setIsRadioDisabled(false); @@ -336,7 +336,7 @@ const QuizPage: React.FC = () => { const displayScore = () => { const score = calculateScore(); - const totalQuestions = quiz?.mcqs?.content?.length || 0; + const totalQuestions = quiz?.mcqs.content.length || 0; setCurrentQuestionIndex(currentQuestionIndex + 1); setShowScore(true); localStorage.setItem('currentQuestionIndex', '0'); @@ -410,11 +410,9 @@ const QuizPage: React.FC = () => { } setQuiz(responseData); const initialSelectedOptions: { [key: number]: number | 0 } = {}; - if (responseData.mcqs && responseData.mcqs.content) { - responseData.mcqs.content.forEach((mcq) => { - initialSelectedOptions[mcq.id] = 0; - }); - } + responseData.mcqs.content.forEach((mcq) => { + initialSelectedOptions[mcq.id] = 0; + }); setSelectedOptions(initialSelectedOptions); setQuizIdAvailable(true); // Set quizIdAvailable to true once quiz data is fetched } catch (error) { @@ -457,7 +455,7 @@ const QuizPage: React.FC = () => { Are you sure you want to exit the quiz? - {quiz && quiz.mcqs && Array.isArray(quiz.mcqs.content) && quiz.mcqs.content.length === 0 &&
No questions generated.
} + {quiz && quiz.mcqs && Array.isArray(quiz.mcqs) && quiz.mcqs.content.length === 0 &&
No questions generated.
} {!isQuizOngoing && (
@@ -498,17 +496,17 @@ const QuizPage: React.FC = () => {
- Question {currentQuestionIndex + 1} of {quiz?.mcqs?.content?.length || 0} + Question {currentQuestionIndex + 1} of {quiz?.mcqs?.content.length || 0}
-
{currentQuestion.skills ? currentQuestion.skills.map((skill) => skill.name).join(', ') : ''}
+
{currentQuestion.skills.map((skill) => skill.name).join(', ')}
- {currentQuestion.options && currentQuestion.options.map((option) => ( + {currentQuestion.options.map((option) => (