fixed bug with start node when reloading the tree

This commit is contained in:
azivner 2017-11-05 09:52:28 -05:00
parent ae23f2ea84
commit df7a39776d
2 changed files with 15 additions and 14 deletions

View File

@ -3,6 +3,7 @@
const noteTree = (function() { const noteTree = (function() {
const noteDetailEl = $('#note-detail'); const noteDetailEl = $('#note-detail');
const treeEl = $("#tree"); const treeEl = $("#tree");
let startNoteId = null;
let treeLoadTime = null; let treeLoadTime = null;
let clipboardNoteId = null; let clipboardNoteId = null;
@ -55,7 +56,7 @@ const noteTree = (function() {
}); });
} }
function initFancyTree(notes, startNoteId) { function initFancyTree(notes) {
const keybindings = { const keybindings = {
"insert": node => { "insert": node => {
const parentKey = treeUtils.getParentKey(node); const parentKey = treeUtils.getParentKey(node);
@ -188,10 +189,19 @@ const noteTree = (function() {
treeEl.contextmenu(contextMenu.contextMenuSettings); treeEl.contextmenu(contextMenu.contextMenuSettings);
} }
async function reload() {
const treeResp = await loadTree();
// this will also reload the note content
await treeEl.fancytree('getTree').reload(treeResp.notes);
encryption.decryptTreeItems();
}
function loadTree() { function loadTree() {
return $.get(baseApiUrl + 'tree').then(resp => { return $.get(baseApiUrl + 'tree').then(resp => {
const notes = resp.notes; const notes = resp.notes;
let startNoteId = resp.start_note_id; startNoteId = resp.start_note_id;
treeLoadTime = resp.tree_load_time; treeLoadTime = resp.tree_load_time;
// add browser ID header to all AJAX requests // add browser ID header to all AJAX requests
@ -212,11 +222,7 @@ const noteTree = (function() {
}); });
} }
$(() => { $(() => loadTree().then(resp => initFancyTree(resp.notes)));
loadTree().then(resp => {
initFancyTree(resp.notes, resp.startNoteId);
});
});
function collapseTree() { function collapseTree() {
treeEl.fancytree("getRootNode").visit(node => { treeEl.fancytree("getRootNode").visit(node => {
@ -289,7 +295,7 @@ const noteTree = (function() {
getTreeLoadTime, getTreeLoadTime,
getClipboardNoteId, getClipboardNoteId,
setClipboardNoteId, setClipboardNoteId,
loadTree, reload,
collapseTree, collapseTree,
scrollToCurrentNote, scrollToCurrentNote,
toggleSearch, toggleSearch,

View File

@ -28,14 +28,9 @@ const status = (function() {
}); });
if (resp.changedTree) { if (resp.changedTree) {
const treeResp = await noteTree.loadTree();
console.log("Reloading tree because of background changes"); console.log("Reloading tree because of background changes");
// this will also reload the note content noteTree.reload();
await treeEl.fancytree('getTree').reload(treeResp.notes);
encryption.decryptTreeItems();
} }
$changesToPushCountEl.html(resp.changesToPushCount); $changesToPushCountEl.html(resp.changesToPushCount);