From 40e1b44565ff74e3f4cc08463d59b3d6e62e7bb7 Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Tue, 1 Jul 2025 22:47:18 +0600 Subject: [PATCH] wip --- src/components/AIQuiz/AIMCQQuestion.tsx | 28 ++++++++++++++++++++----- src/components/AIQuiz/AIQuizContent.tsx | 9 +++++++- src/queries/ai-quiz.ts | 7 ++++++- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/components/AIQuiz/AIMCQQuestion.tsx b/src/components/AIQuiz/AIMCQQuestion.tsx index 5ba752424..41a83fdf4 100644 --- a/src/components/AIQuiz/AIMCQQuestion.tsx +++ b/src/components/AIQuiz/AIMCQQuestion.tsx @@ -2,13 +2,15 @@ import type { QuizQuestion } from '../../queries/ai-quiz'; import { useState } from 'react'; import { cn } from '../../lib/classname'; import { CheckIcon, XIcon, InfoIcon } from 'lucide-react'; +import { markdownToHtml } from '../../lib/markdown'; type AIMCQQuestionProps = { question: QuizQuestion; + onNextQuestion?: () => void; }; export function AIMCQQuestion(props: AIMCQQuestionProps) { - const { question } = props; + const { question, onNextQuestion } = props; const { title: questionText, options, answerExplanation } = question; const [selectedOptions, setSelectedOptions] = useState([]); @@ -32,18 +34,29 @@ export function AIMCQQuestion(props: AIMCQQuestionProps) { }; const handleSubmit = () => { + if (isSubmitted) { + onNextQuestion?.(); + setSelectedOptions([]); + setIsSubmitted(false); + return; + } + setIsSubmitted(true); }; const canSubmit = selectedOptions.length > 0; + const titleHtml = markdownToHtml(questionText, false); return (
-

{questionText}

+
+
{options.map((option, index) => { const isSelected = selectedOptions.includes(index); - const showCorrectness = isSubmitted && isSelected; const isCorrectOption = option.isCorrect; const isSelectedAndCorrect = @@ -53,6 +66,8 @@ export function AIMCQQuestion(props: AIMCQQuestionProps) { const isNotSelectedAndCorrect = isSubmitted && !isSelected && isCorrectOption; + const html = markdownToHtml(option.title, false); + return (
-

{option.title}

+
); })} @@ -116,7 +134,7 @@ export function AIMCQQuestion(props: AIMCQQuestionProps) { onClick={handleSubmit} disabled={!canSubmit} > - Submit Answer + {isSubmitted ? 'Next Question' : 'Submit Answer'}
); diff --git a/src/components/AIQuiz/AIQuizContent.tsx b/src/components/AIQuiz/AIQuizContent.tsx index 3a8c02fa9..28088b0cb 100644 --- a/src/components/AIQuiz/AIQuizContent.tsx +++ b/src/components/AIQuiz/AIQuizContent.tsx @@ -21,6 +21,10 @@ export function AIQuizContent(props: AIQuizContentProps) { const hasMoreQuestions = activeQuestionIndex < questions.length - 1; const hasPreviousQuestions = activeQuestionIndex > 0; + console.log('-'.repeat(20)); + console.log(questions); + console.log('-'.repeat(20)); + return (
@@ -40,7 +44,10 @@ export function AIQuizContent(props: AIQuizContentProps) {
{activeQuestion && activeQuestion.type === 'mcq' && ( - + setActiveQuestionIndex(activeQuestionIndex + 1)} + /> )}
); diff --git a/src/queries/ai-quiz.ts b/src/queries/ai-quiz.ts index a8f67c680..72b43aa41 100644 --- a/src/queries/ai-quiz.ts +++ b/src/queries/ai-quiz.ts @@ -148,7 +148,7 @@ export type QuizQuestion = { export function generateAiQuizQuestions(questionData: string): QuizQuestion[] { const questions: QuizQuestion[] = []; - const lines = questionData.split('\n').map((line) => line.trim()); + const lines = questionData.split('\n'); let currentQuestion: QuizQuestion | null = null; let context: 'question' | 'explanation' | 'option' | null = null; @@ -214,6 +214,11 @@ export function generateAiQuizQuestions(questionData: string): QuizQuestion[] { continue; } + console.log('-'.repeat(20)); + console.log('CONTEXT:', context); + console.log('LINE:', line); + console.log('-'.repeat(20)); + if (context === 'question') { currentQuestion.title += `\n${line}`; } else if (context === 'explanation') {