fix: text updating in edit

This commit is contained in:
Artemy 2023-04-29 09:35:15 +03:00
parent b8c7c69012
commit 80858f53d9

View file

@ -37,6 +37,8 @@ function NotePage() {
let note = notes[params.id]; let note = notes[params.id];
let [edit, setEdit] = useState(false); let [edit, setEdit] = useState(false);
let [text, setText] = useState(note.text);
let [name, setName] = useState(note.name);
return ( return (
<div className=""> <div className="">
@ -52,17 +54,17 @@ function NotePage() {
<> <>
<NoteNameInput <NoteNameInput
value={note.name} value={note.name}
onChange={(e) => (note.name = e.target.value)} onChange={(e) => setName(e.target.value)}
/> />
<NoteTextArea <NoteTextArea
value={note.text} value={note.text}
onChange={(e) => (note.text = e.target.value)} onChange={(e) => setText(e.target.value)}
/> />
<div className="grid grid-cols-1 lg:grid-cols-2 justify-items-center w-full"> <div className="grid grid-cols-1 lg:grid-cols-2 justify-items-center w-full">
<NotesAdditionalSettings <NotesAdditionalSettings
noteText={note.text} noteText={note.text}
onClick={(text) => { onClick={(text) => {
note.text = text; setText(text);
}} }}
/> />
</div> </div>
@ -81,11 +83,12 @@ function NotePage() {
text={locals.Edit} text={locals.Edit}
icon={PencilIcon} icon={PencilIcon}
onClick={() => { onClick={() => {
setEdit(!edit); notes[params.id].name = name;
notes[params.id].text = text;
if (edit) { localStorage.setObj("Notes", notes);
localStorage.setObj("Notes", notes);
} setEdit(!edit);
}} }}
/> />
{!edit && ( {!edit && (