multi line paste for add course and edit course

This commit is contained in:
rgrgogu
2026-07-30 20:35:38 +08:00
parent f9616b7219
commit 3ccbda7a00
3 changed files with 47 additions and 5 deletions
@@ -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 (
<div className="space-y-2">
<Label className="text-xs text-muted-foreground uppercase tracking-wide">Objectives</Label>
{fields.map((f, oi) => (
<div key={f.id} className="flex items-center gap-2">
<Input {...register(`lessons.${lessonIndex}.objectives.${oi}.value`)} placeholder="Learning objective" />
<Input
{...register(`lessons.${lessonIndex}.objectives.${oi}.value`)}
placeholder="Learning objective"
onPaste={(e) => handleObjectivePaste(e, oi)}
/>
<Button
type="button"
variant="ghost"