Module Update
Some checks failed
CI / build-and-test (push) Failing after 1m31s
CI / deploy (push) Has been skipped

This commit is contained in:
SpecialX
2025-12-30 14:42:30 +08:00
parent f1797265b2
commit e7c902e8e1
148 changed files with 19317 additions and 113 deletions

View File

@@ -0,0 +1,76 @@
import { notFound } from "next/navigation"
import { ExamAssembly } from "@/modules/exams/components/exam-assembly"
import { getExamById } from "@/modules/exams/data-access"
import { getQuestions } from "@/modules/questions/data-access"
import type { Question } from "@/modules/questions/types"
import type { ExamNode } from "@/modules/exams/components/assembly/selected-question-list"
import { createId } from "@paralleldrive/cuid2"
export default async function BuildExamPage({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params
const exam = await getExamById(id)
if (!exam) return notFound()
// Fetch all available questions (for selection pool)
// In a real app, this might be paginated or filtered by exam subject/grade
const { data: questionsData } = await getQuestions({ pageSize: 100 })
const questionOptions: Question[] = questionsData.map((q) => ({
id: q.id,
content: q.content as any,
type: q.type as any,
difficulty: q.difficulty ?? 1,
createdAt: new Date(q.createdAt),
updatedAt: new Date(q.updatedAt),
author: q.author ? {
id: q.author.id,
name: q.author.name || "Unknown",
image: q.author.image || null
} : null,
knowledgePoints: (q.questionsToKnowledgePoints || []).map((kp) => ({
id: kp.knowledgePoint.id,
name: kp.knowledgePoint.name
}))
}))
const initialSelected = (exam.questions || []).map(q => ({
id: q.id,
score: q.score || 0
}))
// Prepare initialStructure on server side to avoid hydration mismatch with random IDs
let initialStructure: ExamNode[] = exam.structure as ExamNode[] || []
if (initialStructure.length === 0 && initialSelected.length > 0) {
initialStructure = initialSelected.map(s => ({
id: createId(), // Generate stable ID on server
type: 'question',
questionId: s.id,
score: s.score
}))
}
return (
<div className="flex h-full flex-col space-y-8 p-8">
<div className="flex items-center justify-between">
<div>
<h2 className="text-2xl font-bold tracking-tight">Build Exam</h2>
<p className="text-muted-foreground">Add questions and adjust scores.</p>
</div>
</div>
<ExamAssembly
examId={exam.id}
title={exam.title}
subject={exam.subject}
grade={exam.grade}
difficulty={exam.difficulty}
totalScore={exam.totalScore}
durationMin={exam.durationMin}
initialSelected={initialSelected}
initialStructure={initialStructure}
questionOptions={questionOptions}
/>
</div>
)
}