1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-08-13 22:12:50 +02:00

Optimised saving notes

This commit is contained in:
Laurent Cozic
2017-07-16 00:09:04 +01:00
parent 4152fcec5e
commit 12c163ef73
3 changed files with 6 additions and 16 deletions

View File

@@ -25,15 +25,11 @@ class Command extends BaseCommand {
async action(args) {
let watcher = null;
let newNote = null;
let hasSaved = false;
const onFinishedEditing = async () => {
if (watcher) watcher.close();
app().vorpal().show();
if (!hasSaved && newNote) {
await Note.delete(newNote.id);
newNote = null;
}
newNote = null;
this.log(_('Done editing.'));
}
@@ -50,8 +46,8 @@ class Command extends BaseCommand {
let note = await app().loadItem(BaseModel.TYPE_NOTE, title);
if (!note) {
newNote = await Note.save({ parent_id: app().currentFolder().id });
note = newNote;
newNote = await Note.save({ title: title, parent_id: app().currentFolder().id });
note = await Note.load(newNote.id);
}
let editorPath = textEditorPath();
@@ -80,7 +76,6 @@ class Command extends BaseCommand {
if (watchTimeout) return;
watchTimeout = setTimeout(async () => {
hasSaved = true;
let updatedNote = await fs.readFile(tempFilePath, 'utf8');
updatedNote = await Note.unserializeForEdit(updatedNote);
updatedNote.id = note.id;

View File

@@ -227,17 +227,12 @@ class Note extends BaseItem {
if (isNew && !o.source) o.source = Setting.value('appName');
if (isNew && !o.source_application) o.source_application = Setting.value('appId');
//return super.save(o, options);
return super.save(o, options).then((result) => {
// 'result' could be a partial one at this point (if, for example, only one property of it was saved)
// so call this.preview() so that the right fields are populated.
return this.load(result.id);
}).then((note) => {
return super.save(o, options).then((note) => {
this.dispatch({
type: 'NOTES_UPDATE_ONE',
note: note,
});
return note;
});
}

View File

@@ -158,7 +158,7 @@ const reducer = (state = defaultState, action) => {
for (let i = 0; i < newNotes.length; i++) {
let n = newNotes[i];
if (n.id == action.note.id) {
newNotes[i] = action.note;
newNotes[i] = Object.assign(newNotes[i], action.note);
found = true;
break;
}