From 3ccbda7a001f75aa46a75300a7b576464f2bb1b7 Mon Sep 17 00:00:00 2001 From: rgrgogu Date: Thu, 30 Jul 2026 20:35:38 +0800 Subject: [PATCH] multi line paste for add course and edit course --- .../admin/pages/courses/lessons/AddLesson.jsx | 19 +++++++++++++++++-- .../pages/courses/lessons/EditLesson.jsx | 14 +++++++++++++- .../pages/library/units/AddLibraryUnit.jsx | 19 +++++++++++++++++-- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/modules/admin/pages/courses/lessons/AddLesson.jsx b/src/modules/admin/pages/courses/lessons/AddLesson.jsx index cfa7f49..f9f5fa2 100644 --- a/src/modules/admin/pages/courses/lessons/AddLesson.jsx +++ b/src/modules/admin/pages/courses/lessons/AddLesson.jsx @@ -56,7 +56,18 @@ function FieldError({ message }) { // ─── Step 1 — Details ─────────────────────────────────────────────────────────── function StepDetails({ register, errors, control }) { - const { fields, append, remove } = useFieldArray({ control, name: "objectives" }); + const { fields, append, remove, insert, update } = useFieldArray({ control, name: "objectives" }); + + const handleObjectivePaste = (e, index) => { + const text = e.clipboardData.getData("text"); + const lines = text.split(/\r\n|\r|\n/).map((l) => l.trim()).filter(Boolean); + if (lines.length <= 1) return; + e.preventDefault(); + update(index, { value: lines[0] }); + lines.slice(1).forEach((line, i) => { + insert(index + 1 + i, { value: line }); + }); + }; return (
@@ -101,7 +112,11 @@ function StepDetails({ register, errors, control }) { {fields.map((field, index) => (
- + handleObjectivePaste(e, index)} + />
diff --git a/src/modules/admin/pages/library/units/AddLibraryUnit.jsx b/src/modules/admin/pages/library/units/AddLibraryUnit.jsx index 776c74d..e8c100b 100644 --- a/src/modules/admin/pages/library/units/AddLibraryUnit.jsx +++ b/src/modules/admin/pages/library/units/AddLibraryUnit.jsx @@ -126,14 +126,29 @@ function StepUnit({ register, errors, control, setValue, tierCategories }) { // ─── Step 2 — Lessons ────────────────────────────────────────────────────────── function LessonObjectives({ control, register, lessonIndex }) { - const { fields, append, remove } = useFieldArray({ control, name: `lessons.${lessonIndex}.objectives` }); + const { fields, append, remove, insert, update } = useFieldArray({ control, name: `lessons.${lessonIndex}.objectives` }); + + const handleObjectivePaste = (e, oi) => { + const text = e.clipboardData.getData("text"); + const lines = text.split(/\r\n|\r|\n/).map((l) => l.trim()).filter(Boolean); + if (lines.length <= 1) return; + e.preventDefault(); + update(oi, { value: lines[0] }); + lines.slice(1).forEach((line, i) => { + insert(oi + 1 + i, { value: line }); + }); + }; return (
{fields.map((f, oi) => (
- + handleObjectivePaste(e, oi)} + />