feat: enhance textbook reader with anchor text support and improve knowledge point management

This commit is contained in:
SpecialX
2026-01-16 10:22:16 +08:00
parent 9bfc621d3f
commit bb4555f611
44 changed files with 6284 additions and 2090 deletions

View File

@@ -60,6 +60,9 @@ interface CreateQuestionDialogProps {
open: boolean
onOpenChange: (open: boolean) => void
initialData?: Question | null
defaultKnowledgePointIds?: string[]
defaultContent?: string
defaultType?: "single_choice" | "multiple_choice" | "text" | "judgment" | "composite"
}
function getInitialTextFromContent(content: unknown) {
@@ -97,7 +100,14 @@ function getInitialOptionsFromContent(content: unknown) {
return mapped.length > 0 ? mapped : undefined
}
export function CreateQuestionDialog({ open, onOpenChange, initialData }: CreateQuestionDialogProps) {
export function CreateQuestionDialog({
open,
onOpenChange,
initialData,
defaultKnowledgePointIds = [],
defaultContent = "",
defaultType = "single_choice"
}: CreateQuestionDialogProps) {
const router = useRouter()
const [isPending, setIsPending] = useState(false)
const isEdit = !!initialData
@@ -105,9 +115,9 @@ export function CreateQuestionDialog({ open, onOpenChange, initialData }: Create
const form = useForm<QuestionFormValues>({
resolver: zodResolver(QuestionFormSchema),
defaultValues: {
type: initialData?.type || "single_choice",
type: initialData?.type || defaultType,
difficulty: initialData?.difficulty || 1,
content: getInitialTextFromContent(initialData?.content),
content: getInitialTextFromContent(initialData?.content) || defaultContent,
options:
getInitialOptionsFromContent(initialData?.content) ?? [
{ label: "Option A", value: "A", isCorrect: true },
@@ -130,16 +140,16 @@ export function CreateQuestionDialog({ open, onOpenChange, initialData }: Create
})
} else {
form.reset({
type: "single_choice",
type: defaultType,
difficulty: 1,
content: "",
content: defaultContent,
options: [
{ label: "Option A", value: "A", isCorrect: true },
{ label: "Option B", value: "B", isCorrect: false },
],
})
}
}, [initialData, form, open])
}, [initialData, form, open, defaultContent, defaultType])
const questionType = form.watch("type")
@@ -184,7 +194,7 @@ export function CreateQuestionDialog({ open, onOpenChange, initialData }: Create
type: data.type,
difficulty: data.difficulty,
content: buildContent(data),
knowledgePointIds: [],
knowledgePointIds: isEdit ? [] : defaultKnowledgePointIds,
}
const fd = new FormData()
fd.set("json", JSON.stringify(payload))