Skip to content

Commit 6ee4272

Browse files
committed
Fix save note func
1 parent f04449c commit 6ee4272

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/App.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,19 +319,20 @@ class App extends Component {
319319
}
320320

321321
handleSaveNote(e, note) {
322-
var notebody = html2md.turndown(marked(marked(this.state.notebody)));
322+
const notebody = html2md.turndown(marked(marked(note.notebody)));
323+
const notetitle = document.getElementById("notetitle").value;
323324
this.setState((prevState) => {
324325
const updatedNotes = prevState.allnotes.map((noteitem) => {
325326
if (noteitem.noteid === note.noteid) {
326-
noteitem.title = document.getElementById("notetitle").value;
327+
noteitem.title = notetitle;
327328
noteitem.body = notebody;
328329
noteitem.activepage = "viewnote";
329330
}
330331
return noteitem;
331332
});
332333
return {
333334
noteid: note.noteid,
334-
notetitle: document.getElementById("notetitle").value,
335+
notetitle: notetitle,
335336
notebody: notebody,
336337
activepage: "viewnote",
337338
action: note.action,
@@ -342,7 +343,7 @@ class App extends Component {
342343
if (note.action == "addnote") {
343344
this.state.allnotes.push({
344345
noteid: note.noteid,
345-
notetitle: document.getElementById("notetitle").value,
346+
notetitle: notetitle,
346347
notebody: notebody,
347348
activepage: "viewnote",
348349
created_at: Date.now(),
@@ -352,7 +353,7 @@ class App extends Component {
352353
// Update IndexedDB
353354
this.handleIndexedDB("addnote", {
354355
noteid: note.noteid,
355-
title: document.getElementById("notetitle").value,
356+
title: notetitle,
356357
body: notebody,
357358
created_at: Date.now(),
358359
updated_at: Date.now(),
@@ -361,7 +362,7 @@ class App extends Component {
361362
// if note.action == "editnote"
362363
this.handleIndexedDB("update", {
363364
noteid: note.noteid,
364-
title: document.getElementById("notetitle").value,
365+
title: notetitle,
365366
body: notebody,
366367
updated_at: Date.now(),
367368
});

src/NoteEditor.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,15 @@ function NoteEditor(props) {
142142
textareaRef.current.setSelectionRange(cusor.start, cusor.end);
143143
};
144144
const handleBodyChange = (e) => {
145-
props.handleNoteEditor(e);
145+
// props.handleNoteEditor(e);
146146
setBodyTxt(e.target.value);
147147
setCursor({
148148
start: e.target.selectionStart,
149149
end: e.target.selectionEnd,
150150
});
151151
};
152152
const handleTitleChange = (e) => {
153-
props.handleNoteEditor(e);
153+
// props.handleNoteEditor(e);
154154
setTitle(e.target.value);
155155
};
156156

@@ -320,6 +320,14 @@ function NoteEditor(props) {
320320
return props.handleClickHomeBtn();
321321
};
322322

323+
// Handle Save Noye Button Click
324+
325+
const handleSave = (e) => {
326+
note.notetitle = title;
327+
note.notebody = bodytxt;
328+
props.handleSaveNote(e, note);
329+
};
330+
323331
return (
324332
<div className="right-row">
325333
<div></div>
@@ -330,7 +338,7 @@ function NoteEditor(props) {
330338
type="text"
331339
id="notetitle"
332340
data-action={note.action}
333-
value={note.notetitle}
341+
value={title}
334342
placeholder="Title"
335343
autoComplete="off"
336344
ref={titleRef}
@@ -470,7 +478,7 @@ function NoteEditor(props) {
470478
onKeyDown={(e) => handleKeyEvent(e)}
471479
data-action={note.action}
472480
value={bodytxt}
473-
id="notetitle"
481+
id="notebody"
474482
data-action={note.action}
475483
ref={textareaRef}
476484
onBlur={(e) => handleBlurEvent(e)}
@@ -486,7 +494,7 @@ function NoteEditor(props) {
486494
<div className="saveCancelBar">
487495
<i
488496
className="far fa-save btn-save-cancel fa-2x"
489-
onClick={(e) => props.handleSaveNote(e, note)}
497+
onClick={(e) => handleSave(e)}
490498
data-action={note.action}
491499
></i>
492500
<i

0 commit comments

Comments
 (0)