diff --git a/ElectronClient/app/gui/NoteText.jsx b/ElectronClient/app/gui/NoteText.jsx index af44bb837..a3075240c 100644 --- a/ElectronClient/app/gui/NoteText.jsx +++ b/ElectronClient/app/gui/NoteText.jsx @@ -124,11 +124,15 @@ class NoteTextComponent extends React.Component { }, 500); } - async reloadNote(props) { + async reloadNote(props, options = null) { + if (!options) options = {}; + if (!('noReloadIfLocalChanges' in options)) options.noReloadIfLocalChanges = false; + const noteId = props.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 the note hasn't been changed, exit now if (this.state.note && note) { @@ -166,7 +170,7 @@ class NoteTextComponent extends React.Component { } if ('syncStarted' in nextProps && !nextProps.syncStarted && !this.isModified()) { - await this.reloadNote(nextProps); + await this.reloadNote(nextProps, { noReloadIfLocalChanges: true }); } } diff --git a/ReactNativeClient/lib/components/shared/note-screen-shared.js b/ReactNativeClient/lib/components/shared/note-screen-shared.js index ceb8a21ac..b7d5a6d83 100644 --- a/ReactNativeClient/lib/components/shared/note-screen-shared.js +++ b/ReactNativeClient/lib/components/shared/note-screen-shared.js @@ -13,11 +13,11 @@ shared.noteExists = async function(noteId) { shared.saveNoteButton_press = async function(comp) { let note = Object.assign({}, comp.state.note); - // Note has been deleted while user was modifying it. In that, we + // Note has been deleted while user was modifying it. In that case, we // 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); + // reg.logger().info('Saving note: ', note); if (!note.parent_id) { let folder = await Folder.defaultFolder(); @@ -46,9 +46,19 @@ shared.saveNoteButton_press = async function(comp) { const savedNote = await Note.save(diff); + const stateNote = comp.state.note; // Re-assign any property that might have changed during saving (updated_time, etc.) note = Object.assign(note, savedNote); + if (stateNote) { + // But we preserve the current title and body because + // the user might have changed them between the time + // saveNoteButton_press was called and the note was + // saved (it's done asynchronously) + note.title = stateNote.title; + note.body = stateNote.body; + } + comp.setState({ lastSavedNote: Object.assign({}, note), note: note, @@ -65,7 +75,7 @@ shared.saveOneProperty = async function(comp, name, value) { // 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 property: ', note.id, name, value); + // reg.logger().info('Saving note property: ', note.id, name, value); if (note.id) { let toSave = { id: note.id };