From bc444ea7375647388320824e66698cc76f796244 Mon Sep 17 00:00:00 2001 From: ectasy663 Date: Thu, 9 Jul 2026 09:47:10 +0530 Subject: [PATCH] Fix UI bugs: history page fallback, admin page typescript type, cbt page math rendering --- backend/main.py | 39 +++++++-------- src/app/admin/tests/page.tsx | 4 +- .../cbt/history/[attemptId]/page.tsx | 47 +++++++++++++------ src/app/dashboard/cbt/page.tsx | 15 ++++-- 4 files changed, 66 insertions(+), 39 deletions(-) diff --git a/backend/main.py b/backend/main.py index b59c258..255925c 100644 --- a/backend/main.py +++ b/backend/main.py @@ -481,17 +481,17 @@ def get_admin_tests(session: Session = Depends(get_session)): return tests class ManualQuestionInput(BaseModel): - section: str - text_en: str - text_hi: Optional[str] = None - options_en: List[str] - options_hi: Optional[List[str]] = None - correct_answer: str - type: str = "SingleChoice" - topic: str = "General" - difficulty: str = "Medium" - marks: int = 4 - negative_marks: int = 1 + section: str = "General" + subject: str + topic: str + subtopic: str + difficulty: str + type: str + question_text: str + options: Optional[Dict[str, Any]] = None + correct_answer: Dict[str, Any] + solution_text: str + language: str class ManualTestCreate(BaseModel): title: str @@ -574,16 +574,17 @@ def create_manual_test( for q_data in data.questions_json: q_obj = models.Question( - text_en=q_data.text_en, - text_hi=q_data.text_hi, - options_en=q_data.options_en, - options_hi=q_data.options_hi, - correct_answer=q_data.correct_answer, - type=q_data.type, + subject=q_data.subject, topic=q_data.topic, + subtopic=q_data.subtopic, difficulty=q_data.difficulty, - marks=q_data.marks, - negative_marks=q_data.negative_marks + type=models.QuestionTypeEnum(q_data.type), + question_text=q_data.question_text, + options=q_data.options, + correct_answer=q_data.correct_answer, + solution_text=q_data.solution_text, + language=models.MediumEnum(q_data.language), + created_by=data.admin_id ) session.add(q_obj) session.commit() diff --git a/src/app/admin/tests/page.tsx b/src/app/admin/tests/page.tsx index fa652a8..54413ff 100644 --- a/src/app/admin/tests/page.tsx +++ b/src/app/admin/tests/page.tsx @@ -153,7 +153,7 @@ export default function AdminTestsPage() { setScheduledDate(date)} + onChange={(date: Date | null) => setScheduledDate(date)} showTimeSelect timeFormat="HH:mm" timeIntervals={15} @@ -167,7 +167,7 @@ export default function AdminTestsPage() { setEndDate(date)} + onChange={(date: Date | null) => setEndDate(date)} showTimeSelect timeFormat="HH:mm" timeIntervals={15} diff --git a/src/app/dashboard/cbt/history/[attemptId]/page.tsx b/src/app/dashboard/cbt/history/[attemptId]/page.tsx index a16d1ef..7c2af57 100644 --- a/src/app/dashboard/cbt/history/[attemptId]/page.tsx +++ b/src/app/dashboard/cbt/history/[attemptId]/page.tsx @@ -6,6 +6,10 @@ import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { ArrowLeft, CheckCircle2, XCircle, Clock, Award } from "lucide-react"; +import ReactMarkdown from "react-markdown"; +import remarkMath from "remark-math"; +import rehypeKatex from "rehype-katex"; +import "katex/dist/katex.min.css"; export default function AttemptHistoryPage({ params }: { params: Promise<{ attemptId: string }> }) { const { attemptId } = use(params); @@ -123,7 +127,11 @@ export default function AttemptHistoryPage({ params }: { params: Promise<{ attem {idx + 1}
-

{q.question_text || q.text_en || q.text}

+
+ + {q.question_text || q.text_en || q.text || ""} + +
{q.topic} {q.difficulty} @@ -140,28 +148,39 @@ export default function AttemptHistoryPage({ params }: { params: Promise<{ attem

Your Answer

-
- {ans.is_subjective || q.type === 'Subjective' || q.type === 'Numerical' - ? (ans.selected_answer || 'Not Attempted') - : (q.options && q.options[ans.selected_answer] ? `${ans.selected_answer}) ${q.options[ans.selected_answer]}` : ans.selected_answer || 'Not Attempted')} +
+ + {ans.is_subjective || q.type === 'Subjective' || q.type === 'Numerical' + ? (ans.selected_answer || 'Not Attempted') + : (q.options && q.options[ans.selected_answer] ? `${ans.selected_answer}) ${q.options[ans.selected_answer]}` : ans.selected_answer || 'Not Attempted')} +

Correct Answer

-
- {ans.is_subjective || q.type === 'Subjective' || q.type === 'Numerical' - ? (q.correct_answer?.value || q.correct_answer?.correct || 'Subjective text') - : (q.options && q.options[q.correct_answer?.correct || q.correct_answer?.value] - ? `${q.correct_answer?.correct || q.correct_answer?.value}) ${q.options[q.correct_answer?.correct || q.correct_answer?.value]}` - : (q.correct_answer?.correct || q.correct_answer?.value || 'N/A'))} +
+ + {ans.is_subjective || q.type === 'Subjective' || q.type === 'Numerical' + ? (q.correct_answer?.value || q.correct_answer?.correct || q.correct_answer?.selected || 'Subjective text') + : (q.options && q.options[q.correct_answer?.correct || q.correct_answer?.value || q.correct_answer?.selected] + ? `${q.correct_answer?.correct || q.correct_answer?.value || q.correct_answer?.selected}) ${q.options[q.correct_answer?.correct || q.correct_answer?.value || q.correct_answer?.selected]}` + : (q.correct_answer?.correct || q.correct_answer?.value || q.correct_answer?.selected || 'N/A'))} +
- {q.correct_answer?.explanation && ( + {(q.solution_text || q.correct_answer?.explanation) && (
-

Explanation:

-

{q.correct_answer.explanation}

+

+ + Detailed Solution: +

+
+ + {q.solution_text || q.correct_answer?.explanation || ""} + +
)} diff --git a/src/app/dashboard/cbt/page.tsx b/src/app/dashboard/cbt/page.tsx index 4a7b1cd..31bc64e 100644 --- a/src/app/dashboard/cbt/page.tsx +++ b/src/app/dashboard/cbt/page.tsx @@ -126,9 +126,16 @@ export default function CBTPage() {
- - {exam.type} Test - +
+ + {exam.type} Test + + {exam.exam_pattern && ( + + {exam.exam_pattern} + + )} +
{isUpcoming ? ( Upcoming @@ -211,7 +218,7 @@ export default function CBTPage() {
{Math.round(attempt.accuracy)}%
-