From 8c996a75ef7dafc76cceddb88048c25973d21865 Mon Sep 17 00:00:00 2001 From: azivner Date: Sun, 5 Nov 2017 10:06:49 -0500 Subject: [PATCH] reloading tree now doesn't force note reload --- public/javascripts/note_editor.js | 16 ++++++++++++++++ public/javascripts/note_tree.js | 4 +--- public/javascripts/status.js | 11 ++++++++--- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/public/javascripts/note_editor.js b/public/javascripts/note_editor.js index 8853dfd3f..20a2f054b 100644 --- a/public/javascripts/note_editor.js +++ b/public/javascripts/note_editor.js @@ -36,6 +36,20 @@ const noteEditor = (function() { isNoteChanged = true; } + async function reload() { + // no saving here + + await loadNoteToEditor(getCurrentNoteId()); + } + + async function switchToNote(noteId) { + if (getCurrentNoteId() !== noteId) { + await saveNoteIfChanged(); + + await loadNoteToEditor(noteId); + } + } + async function saveNoteIfChanged() { if (!isNoteChanged) { return; @@ -247,6 +261,8 @@ const noteEditor = (function() { setInterval(saveNoteIfChanged, 5000); return { + reload, + switchToNote, saveNoteIfChanged, updateNoteFromInputs, saveNoteToServer, diff --git a/public/javascripts/note_tree.js b/public/javascripts/note_tree.js index d5433a49a..73211f98e 100644 --- a/public/javascripts/note_tree.js +++ b/public/javascripts/note_tree.js @@ -107,7 +107,7 @@ const noteTree = (function() { activate: (event, data) => { const node = data.node.data; - noteEditor.saveNoteIfChanged().then(() => noteEditor.loadNoteToEditor(node.note_id)); + noteEditor.switchToNote(node.note_id); }, expand: (event, data) => { setExpandedToServer(data.node.key, true); @@ -119,8 +119,6 @@ const noteTree = (function() { if (startNoteId) { data.tree.activateKey(startNoteId); } - - $(window).resize(); }, hotkeys: { keydown: keybindings diff --git a/public/javascripts/status.js b/public/javascripts/status.js index c389580e9..e001487e3 100644 --- a/public/javascripts/status.js +++ b/public/javascripts/status.js @@ -1,8 +1,7 @@ "use strict"; const status = (function() { - const treeEl = $("#tree"); - const $changesToPushCountEl = $("#changesToPushCount"); + const changesToPushCountEl = $("#changesToPushCount"); async function checkStatus() { const resp = await $.ajax({ @@ -33,7 +32,13 @@ const status = (function() { noteTree.reload(); } - $changesToPushCountEl.html(resp.changesToPushCount); + if (resp.changedCurrentNote) { + message('Reloading note because background change'); + + noteEditor.reload(); + } + + changesToPushCountEl.html(resp.changesToPushCount); } setInterval(checkStatus, 5 * 1000);