From 43f30f40130c30c403944dd8789d14ecc1b3b3f2 Mon Sep 17 00:00:00 2001 From: SpecialX <47072643+wangxiner55@users.noreply.github.com> Date: Sat, 4 Jul 2026 11:32:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(lesson-preparation):=20=E5=B8=88=E7=94=9F?= =?UTF-8?q?=E4=BA=A4=E4=BA=92=E7=BC=96=E8=BE=91=E5=99=A8=EF=BC=88=E5=AF=B9?= =?UTF-8?q?=E8=AF=9D=E8=BD=AE=E6=AC=A1=E5=A2=9E=E5=88=A0=E6=94=B9=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/detail-panel/qa-editor.tsx | 250 ++++++++++++++++++ 1 file changed, 250 insertions(+) create mode 100644 src/modules/lesson-preparation/components/detail-panel/qa-editor.tsx diff --git a/src/modules/lesson-preparation/components/detail-panel/qa-editor.tsx b/src/modules/lesson-preparation/components/detail-panel/qa-editor.tsx new file mode 100644 index 0000000..fb7f9bb --- /dev/null +++ b/src/modules/lesson-preparation/components/detail-panel/qa-editor.tsx @@ -0,0 +1,250 @@ +"use client"; + +import { useTranslations } from "next-intl"; +import { createId } from "@paralleldrive/cuid2"; +import type { InteractionBlockData, QATurn } from "../../types"; +import { useLessonPlanEditor } from "../../hooks/use-lesson-plan-editor"; + +interface Props { + nodeId: string; + data: InteractionBlockData; +} + +export function QaEditor({ nodeId, data }: Props) { + const t = useTranslations("lessonPreparation"); + const updateNode = useLessonPlanEditor((s) => s.updateNode); + + const updateData = (next: InteractionBlockData) => { + updateNode(nodeId, { data: next }); + }; + + const addTurn = () => { + const newTurn: QATurn = { + id: createId(), + role: "teacher", + content: "", + expectedAnswer: "", + order: data.turns.length, + }; + updateData({ ...data, turns: [...data.turns, newTurn] }); + }; + + const updateTurn = (id: string, patch: Partial) => { + updateData({ + ...data, + turns: data.turns.map((t) => (t.id === id ? { ...t, ...patch } : t)), + }); + }; + + const removeTurn = (id: string) => { + updateData({ + ...data, + turns: data.turns + .filter((t) => t.id !== id) + .map((t, i) => ({ ...t, order: i })), + }); + }; + + const moveTurn = (id: string, direction: "up" | "down") => { + const idx = data.turns.findIndex((t) => t.id === id); + if (idx < 0) return; + const newIdx = direction === "up" ? idx - 1 : idx + 1; + if (newIdx < 0 || newIdx >= data.turns.length) return; + const turns = [...data.turns]; + [turns[idx], turns[newIdx]] = [turns[newIdx], turns[idx]]; + updateData({ + ...data, + turns: turns.map((t, i) => ({ ...t, order: i })), + }); + }; + + return ( +
+
+ +