From 1d7f30d441e2c0fb82bfd0750d3a4203c9636390 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Thu, 11 Jan 2018 21:05:34 +0100 Subject: [PATCH] Electron: Fixed logic to save, and make sure scheduled save always happen even when changing note --- ElectronClient/app/gui/NoteText.jsx | 4 +++- .../components/shared/note-screen-shared.js | 19 +------------------ 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/ElectronClient/app/gui/NoteText.jsx b/ElectronClient/app/gui/NoteText.jsx index bff217e0a..cc56b8b97 100644 --- a/ElectronClient/app/gui/NoteText.jsx +++ b/ElectronClient/app/gui/NoteText.jsx @@ -128,13 +128,15 @@ class NoteTextComponent extends React.Component { if (!options) options = {}; if (!('noReloadIfLocalChanges' in options)) options.noReloadIfLocalChanges = false; + await this.saveIfNeeded(); + const stateNoteId = this.state.note ? this.state.note.id : null; const noteId = props.noteId; let loadingNewNote = stateNoteId !== noteId; this.lastLoadedNoteId_ = noteId; const note = noteId ? await Note.load(noteId) : null; if (noteId !== this.lastLoadedNoteId_) return; // Race condition - current note was changed while this one was loading - if (!options.noReloadIfLocalChanges && this.isModified()) return; + if (options.noReloadIfLocalChanges && this.isModified()) return; // If the note hasn't been changed, exit now if (this.state.note && note) { diff --git a/ReactNativeClient/lib/components/shared/note-screen-shared.js b/ReactNativeClient/lib/components/shared/note-screen-shared.js index 5d59dbb47..ca13b1e5e 100644 --- a/ReactNativeClient/lib/components/shared/note-screen-shared.js +++ b/ReactNativeClient/lib/components/shared/note-screen-shared.js @@ -17,14 +17,9 @@ shared.saveNoteButton_press = async function(comp) { // just save a new note by clearing the note ID. if (note.id && !(await shared.noteExists(note.id))) delete note.id; - // reg.logger().info('Saving note: ', note); - if (!note.parent_id) { let folder = await Folder.defaultFolder(); - if (!folder) { - //Log.warn('Cannot save note without a notebook'); - return; - } + if (!folder) return; note.parent_id = folder.id; } @@ -36,18 +31,6 @@ shared.saveNoteButton_press = async function(comp) { titleWasAutoAssigned = true; } - // Save only the properties that have changed - // let diff = null; - // if (!isNew) { - // diff = BaseModel.diffObjects(comp.state.lastSavedNote, note); - // diff.type_ = note.type_; - // diff.id = note.id; - // } else { - // diff = Object.assign({}, note); - // } - - // const savedNote = await Note.save(diff); - let options = {}; if (!isNew) { options.fields = BaseModel.diffObjectsFields(comp.state.lastSavedNote, note);