From 6b74d4f876f3c1ce599104a3d800e64a74077724 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Sun, 17 Nov 2024 13:43:46 -0800 Subject: [PATCH] Update quiz view --- src/components/Course/QuizView.tsx | 34 +++++++++++++++++++----------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/components/Course/QuizView.tsx b/src/components/Course/QuizView.tsx index e9f5fec33..a0cc97059 100644 --- a/src/components/Course/QuizView.tsx +++ b/src/components/Course/QuizView.tsx @@ -37,7 +37,7 @@ export function QuizView(props: QuizViewProps) {
-

+

{lesson.frontmatter.title}

@@ -124,23 +124,33 @@ type QuizItemProps = { export function QuizItem(props: QuizItemProps) { const { id, title, options, onOptionSelectChange, disabled } = props; - const hasWrongAnswer = options.some((item) => item.status === 'wrong'); - const hasCorrectAnswer = options.some((item) => item.status === 'correct'); + const isAttempted = options.some((item) => + ['correct', 'wrong'].includes(item.status ?? ''), + ); + const hasWrongAnswer = + isAttempted && options.some((item) => item.status === 'wrong'); + const hasCorrectAnswer = isAttempted && !hasWrongAnswer; + + console.log(options); return (
{(hasWrongAnswer || hasCorrectAnswer) && ( - Correct + {hasCorrectAnswer ? 'Correct' : 'Wrong'} )} @@ -183,10 +193,10 @@ export function QuizOption(props: QuizOptionProps) {