diff --git a/backend/routers/exam.py b/backend/routers/exam.py index f513ef2..703d4d9 100644 --- a/backend/routers/exam.py +++ b/backend/routers/exam.py @@ -306,8 +306,8 @@ async def submit_answer( db.add(answer_db) # Update session data - answers_data = session.answers_data or [] - answers_data.append({ + existing_answers = session.answers_data or [] + session.answers_data = existing_answers + [{ "question_id": current_question['id'], "answer": answer.answer, "confidence_level": answer.confidence_level, @@ -315,9 +315,8 @@ async def submit_answer( "is_correct": is_correct, "score": ai_score, "feedback": ai_feedback - }) + }] - session.answers_data = answers_data session.current_question += 1 session.status = ExamStatus.IN_PROGRESS.value diff --git a/frontend/src/components/ConversationLogDisplay.tsx b/frontend/src/components/ConversationLogDisplay.tsx index 9293c4a..c0adea6 100644 --- a/frontend/src/components/ConversationLogDisplay.tsx +++ b/frontend/src/components/ConversationLogDisplay.tsx @@ -137,20 +137,20 @@ function ConversationLogDisplay({ sessionId, logFilePath, isVisible, onClose }: return (
-
+
{/* Header */} -
+
-
+

Exam Conversation Log

Session ID: {sessionId}

{logFilePath && ( -

Saved to: {logFilePath}

+

Saved to: {logFilePath}

)}
@@ -158,7 +158,7 @@ function ConversationLogDisplay({ sessionId, logFilePath, isVisible, onClose }:
{/* Content */} -
+
{isLoading && (
@@ -316,7 +316,7 @@ function ConversationLogDisplay({ sessionId, logFilePath, isVisible, onClose }:
{/* Footer */} -
+
{conversationLogPath && ( -

- 💾 - Saved to: {conversationLogPath} +

+ 💾 + Saved to: {conversationLogPath}

)}
diff --git a/frontend/src/pages/UploadPage.tsx b/frontend/src/pages/UploadPage.tsx index 46a0a5c..5675aa8 100644 --- a/frontend/src/pages/UploadPage.tsx +++ b/frontend/src/pages/UploadPage.tsx @@ -11,7 +11,7 @@ import { useState, useCallback } from 'react' import { useDropzone } from 'react-dropzone' import { useNavigate } from 'react-router-dom' import { useExamContext } from '../contexts/ExamContext' -import { uploadMaterial, isValidFileType, formatFileSize, getFileTypeDisplayName } from '../services/examAPI' +import { uploadMaterial, isValidFileType, formatFileSize, getFileTypeDisplayName, getQuestionCount } from '../services/examAPI' import LoadingSpinner from '../components/LoadingSpinner' import QuestionsPopup from '../components/QuestionsPopup' import toast from 'react-hot-toast' @@ -42,6 +42,7 @@ function UploadPage() { // Questions popup state const [showQuestionsPopup, setShowQuestionsPopup] = useState(false) const [questionsPopupMaterial, setQuestionsPopupMaterial] = useState(null) + const [shouldStartExam, setShouldStartExam] = useState(false) // Delete confirmation state const [showDeleteConfirm, setShowDeleteConfirm] = useState(false) @@ -152,15 +153,24 @@ function UploadPage() { if (success) { toast.success(`${questionCount} questions generated successfully!`) + + // If shouldStartExam, start the exam immediately + if (shouldStartExam) { + setShouldStartExam(false) + handleStartExam(selectedMaterial) + } + setShowQuestionModal(false) setSelectedMaterial(null) setCustomQuestionCount('10') // Reset to default } else { toast.error('Failed to generate questions. Please check your OpenAI API key.') + setShouldStartExam(false) } } catch (error) { console.error('Question generation failed:', error) toast.error('Failed to generate questions. Please try again.') + setShouldStartExam(false) } } @@ -175,6 +185,14 @@ function UploadPage() { // Handle material selection for exam const handleStartExam = async (material: any) => { try { + // Check if the material has questions + const questionCount = await getQuestionCount(material.id) + if (questionCount.total_questions === 0 && !shouldStartExam) { + setShouldStartExam(true) + handleGenerateQuestions(material) + return + } + selectMaterial(material) const success = await startExam(material.id) @@ -570,7 +588,9 @@ function UploadPage() {