mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
multi line paste for add course and edit course
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user