diff --git a/app/exam/[id]/page.tsx b/app/exam/[id]/page.tsx index aaed23c..3c56fed 100644 --- a/app/exam/[id]/page.tsx +++ b/app/exam/[id]/page.tsx @@ -27,8 +27,9 @@ export default function ExamPage() { if (fetchedTest?.metadata.time_limit_minutes) { resetTimer(fetchedTest.metadata.time_limit_minutes * 60, () => { // Timer ended → auto-submit exam + stopTimer(); submitExam(type); - router.push(`/categories/${type}s`); + router.push(`/exam/results`); }); } }); @@ -56,6 +57,7 @@ export default function ExamPage() { const handleSubmitExam = async (type: string) => { try { + stopTimer(); setIsSubmitting(true); await submitExam(type); router.push(`/exam/results`); diff --git a/app/exam/results/page.tsx b/app/exam/results/page.tsx index 9a0c524..0c35739 100644 --- a/app/exam/results/page.tsx +++ b/app/exam/results/page.tsx @@ -15,7 +15,7 @@ export default function ResultsPage() { if (!result) { return (
-

No results to display.

+

Redirecting...

); } @@ -46,16 +46,19 @@ export default function ResultsPage() { const correctAnswer = result.correct_answers[idx]; return ( -
+
{}} // disabled in results + onSelect={() => {}} + userAnswer={userAnswer} + correctAnswer={correctAnswer} + showResults={true} /> - {/* Answer feedback */} -
+ {/* Optional answer feedback below the question */} + {/*
{userAnswer === null ? ( Skipped — Correct: {String.fromCharCode(65 + correctAnswer)} @@ -68,7 +71,7 @@ export default function ResultsPage() { Correct Answer: {String.fromCharCode(65 + correctAnswer)} )} -
+
*/}
); })} diff --git a/components/QuestionItem.tsx b/components/QuestionItem.tsx index 121a413..756497f 100644 --- a/components/QuestionItem.tsx +++ b/components/QuestionItem.tsx @@ -9,6 +9,9 @@ interface QuestionItemProps { index: number; selectedAnswer: Answer; onSelect: (answer: Answer) => void; + userAnswer?: Answer; // new + correctAnswer?: Answer; // new + showResults?: boolean; // control whether to highlight or not } const letters = ["A", "B", "C", "D"]; // extend if needed @@ -18,6 +21,9 @@ const QuestionItem: React.FC = ({ index, selectedAnswer, onSelect, + userAnswer, + correctAnswer, + showResults = false, }) => { return (
@@ -25,10 +31,12 @@ const QuestionItem: React.FC = ({ {index + 1}. {question.question}

-
-
- -
+ {!showResults && ( +
+
+ +
+ )}
{question.options.map((opt, optIdx) => { @@ -38,10 +46,41 @@ const QuestionItem: React.FC = ({ : Array.isArray(selectedAnswer) && selectedAnswer.includes(optIdx); + // ✅ logic for coloring after results + let btnClasses = "bg-gray-100 text-gray-900 border-gray-400"; + if (isSelected) { + btnClasses = "bg-blue-600 text-white border-blue-600"; + } + + if (showResults && correctAnswer !== undefined) { + if (question.type === "Single") { + if (userAnswer === optIdx && userAnswer !== correctAnswer) { + btnClasses = "bg-red-500 text-white border-red-600"; // wrong + } + if (correctAnswer === optIdx) { + btnClasses = "bg-green-500 text-white border-green-600"; // correct + } + } else { + // Multi-select case + const userSelected = + Array.isArray(userAnswer) && userAnswer.includes(optIdx); + const isCorrect = + Array.isArray(correctAnswer) && correctAnswer.includes(optIdx); + + if (userSelected && !isCorrect) { + btnClasses = "bg-red-500 text-white border-red-600"; + } + if (isCorrect) { + btnClasses = "bg-green-500 text-white border-green-600"; + } + } + } + return (