mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2025-04-29 14:23:09 +00:00
JSON editor note fix (#3260)
This commit is contained in:
parent
6072e72974
commit
6fa198147b
@ -66,16 +66,47 @@ function Note({
|
|||||||
});
|
});
|
||||||
}, [script, setScript]);
|
}, [script, setScript]);
|
||||||
|
|
||||||
const NoteItem = memo(
|
return (
|
||||||
({ note, index }: { note: Script["notes"][number]; index: number }) => (
|
<>
|
||||||
|
<h3 className="text-xl font-semibold">Notes</h3>
|
||||||
|
{script.notes.map((note, index) => (
|
||||||
|
<NoteItem key={index} note={note} index={index} updateNote={updateNote} removeNote={removeNote} />
|
||||||
|
))}
|
||||||
|
<Button type="button" size="sm" onClick={addNote}>
|
||||||
|
<PlusCircle className="mr-2 h-4 w-4" /> Add Note
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const NoteItem = memo(
|
||||||
|
({
|
||||||
|
note,
|
||||||
|
index,
|
||||||
|
updateNote,
|
||||||
|
removeNote,
|
||||||
|
}: {
|
||||||
|
note: Script["notes"][number];
|
||||||
|
index: number;
|
||||||
|
updateNote: (index: number, key: keyof Script["notes"][number], value: string) => void;
|
||||||
|
removeNote: (index: number) => void;
|
||||||
|
}) => {
|
||||||
|
const inputRef = useRef<HTMLInputElement | null>(null);
|
||||||
|
|
||||||
|
const handleTextChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
updateNote(index, "text", e.target.value);
|
||||||
|
setTimeout(() => {
|
||||||
|
inputRef.current?.focus();
|
||||||
|
}, 0);
|
||||||
|
}, [index, updateNote]);
|
||||||
|
|
||||||
|
return (
|
||||||
<div className="space-y-2 border p-4 rounded">
|
<div className="space-y-2 border p-4 rounded">
|
||||||
<Input
|
<Input
|
||||||
placeholder="Note Text"
|
placeholder="Note Text"
|
||||||
value={note.text}
|
value={note.text}
|
||||||
onChange={(e) => updateNote(index, "text", e.target.value)}
|
onChange={handleTextChange}
|
||||||
ref={(el) => {
|
ref={inputRef}
|
||||||
inputRefs.current[index] = el;
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
<Select
|
<Select
|
||||||
value={note.type}
|
value={note.type}
|
||||||
@ -109,22 +140,11 @@ function Note({
|
|||||||
<Trash2 className="mr-2 h-4 w-4" /> Remove Note
|
<Trash2 className="mr-2 h-4 w-4" /> Remove Note
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
NoteItem.displayName = 'NoteItem';
|
NoteItem.displayName = 'NoteItem';
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<h3 className="text-xl font-semibold">Notes</h3>
|
|
||||||
{script.notes.map((note, index) => (
|
|
||||||
<NoteItem key={index} note={note} index={index} />
|
|
||||||
))}
|
|
||||||
<Button type="button" size="sm" onClick={addNote}>
|
|
||||||
<PlusCircle className="mr-2 h-4 w-4" /> Add Note
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default memo(Note);
|
export default memo(Note);
|
Loading…
x
Reference in New Issue
Block a user