From f63dc30d674ffdf407c6adc12a13c591036aca9a Mon Sep 17 00:00:00 2001 From: jordan Date: Mon, 3 Nov 2025 22:22:18 +0300 Subject: [PATCH 1/3] feat: if no questons, gnerate questions before starting exam --- frontend/src/pages/UploadPage.tsx | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) 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() { @@ -158,7 +158,7 @@ function ConversationLogDisplay({ sessionId, logFilePath, isVisible, onClose }: {/* Content */} -
+
{isLoading && (
@@ -316,7 +316,7 @@ function ConversationLogDisplay({ sessionId, logFilePath, isVisible, onClose }:
{/* Footer */} -
+
From 16410ca5030c0e8edf4cbab79f2495ca2845dcfb Mon Sep 17 00:00:00 2001 From: jordan Date: Mon, 3 Nov 2025 22:49:29 +0300 Subject: [PATCH 3/3] feat: sort materials by upload time --- frontend/src/contexts/ExamContext.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/src/contexts/ExamContext.tsx b/frontend/src/contexts/ExamContext.tsx index 1f13123..a610330 100644 --- a/frontend/src/contexts/ExamContext.tsx +++ b/frontend/src/contexts/ExamContext.tsx @@ -168,7 +168,8 @@ export function ExamProvider({ children }: ExamProviderProps) { setError(null) const response = await examAPI.getMaterials() - setMaterials(response.materials || []) + const sortedMaterials = response.materials.sort((a: Material, b: Material) => b.upload_time.localeCompare(a.upload_time)) + setMaterials(sortedMaterials || []) } catch (err) { console.error('Failed to load materials:', err) setError('Failed to load study materials')