From e3bb896df2e6c5bbe1bc431c039f8228b1dcf1d0 Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Wed, 2 Jul 2025 21:34:26 +0600 Subject: [PATCH] wip --- src/components/AIQuiz/AIMCQQuestion.tsx | 6 +- src/components/AIQuiz/AIQuizContent.tsx | 13 ++- src/components/AIQuiz/AIQuizResults.tsx | 149 ++++++++++++++++++------ 3 files changed, 126 insertions(+), 42 deletions(-) diff --git a/src/components/AIQuiz/AIMCQQuestion.tsx b/src/components/AIQuiz/AIMCQQuestion.tsx index 5686cf686..9198dcfac 100644 --- a/src/components/AIQuiz/AIMCQQuestion.tsx +++ b/src/components/AIQuiz/AIMCQQuestion.tsx @@ -21,7 +21,7 @@ export function AIMCQQuestion(props: AIMCQQuestionProps) { props; const { title: questionText, options, answerExplanation } = question; - const { isSubmitted, selectedOptions = [], status } = questionState; + const { isSubmitted, selectedOptions = [] } = questionState; const canSubmitMultipleAnswers = options.filter((option) => option.isCorrect).length > 1; @@ -32,9 +32,7 @@ export function AIMCQQuestion(props: AIMCQQuestionProps) { } if (!canSubmitMultipleAnswers) { - const newSelectedOptions = selectedOptions.includes(index) - ? selectedOptions.filter((id) => id !== index) - : [...selectedOptions, index]; + const newSelectedOptions = [index]; setSelectedOptions(newSelectedOptions); return; } diff --git a/src/components/AIQuiz/AIQuizContent.tsx b/src/components/AIQuiz/AIQuizContent.tsx index 59122d252..30c00f029 100644 --- a/src/components/AIQuiz/AIQuizContent.tsx +++ b/src/components/AIQuiz/AIQuizContent.tsx @@ -27,11 +27,10 @@ type AIQuizContentProps = { quizSlug?: string; questions: QuizQuestion[]; isLoading?: boolean; - onNewQuiz?: () => void; }; export function AIQuizContent(props: AIQuizContentProps) { - const { quizSlug, questions, isLoading, onNewQuiz } = props; + const { quizSlug, questions, isLoading } = props; const [activeQuestionIndex, setActiveQuestionIndex] = useState(0); const activeQuestion = questions[activeQuestionIndex]; @@ -140,14 +139,18 @@ export function AIQuizContent(props: AIQuizContentProps) { /> )} - {isAllQuestionsSubmitted ? ( + {isAllQuestionsSubmitted && ( {})} + onNewQuiz={() => { + window.location.href = '/ai/quiz'; + }} /> - ) : ( + )} + + {!isAllQuestionsSubmitted && ( <> {activeQuestion && activeQuestion.type === 'mcq' && ( ; @@ -36,54 +43,130 @@ export function AIQuizResults(props: AIQuizResultsProps) { const accuracy = getPercentage(correctCount, totalQuestions); return ( -
+
{correctCount}/{totalQuestions}
-

- Great job! You answered {correctCount} out of {totalQuestions} questions - correctly — that's {accuracy}% accuracy! +

+ Great job! You answered{' '} + {correctCount} out of{' '} + {totalQuestions} questions correctly + with {accuracy}% accuracy.

-
-
- -
{correctCount}
-
Correct
-
+
+ {states.map((state, quizIndex) => { + const { status } = state; -
- -
{incorrectCount}
-
Incorrect
-
+ const isCorrect = status === 'correct'; + const isIncorrect = status === 'incorrect'; + const isSkipped = status === 'skipped'; -
- -
{skippedCount}
-
Skipped
-
+ return ( +
+ {isCorrect && } + {isIncorrect && } + {isSkipped && } +
+ ); + })}
-
-
+ +
+ } onClick={onRetry} - className="flex items-center gap-2 rounded-lg border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50" - > - - Try Again - - + />
); } + +type ResultCardProps = { + count: number; + label: string; + icon: React.ReactNode; + className?: string; +}; + +export function ResultCard(props: ResultCardProps) { + const { count, label, icon, className } = props; + + return ( +
+ {icon} +
{count}
+
{label}
+
+ ); +} + +type ResultActionProps = { + label: string; + icon: React.ReactNode; + onClick: () => void; + className?: string; +}; + +export function ResultAction(props: ResultActionProps) { + const { label, icon, onClick, className } = props; + + return ( + + ); +}