feat: enhance textbook reader with anchor text support and improve knowledge point management
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user