From 9873dd1242f8dd7061ce0febdf9461fac7a93cfb Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 28 Aug 2020 14:29:20 +0200 Subject: [PATCH] fix creating new note --- src/public/app/entities/note_short.js | 6 +++++- src/public/app/widgets/note_tree.js | 14 +++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/public/app/entities/note_short.js b/src/public/app/entities/note_short.js index 211e2a7ac..cfa387ce9 100644 --- a/src/public/app/entities/note_short.js +++ b/src/public/app/entities/note_short.js @@ -56,6 +56,10 @@ class NoteShort { } addParent(parentNoteId, branchId) { + if (parentNoteId === 'none') { + return; + } + if (!this.parents.includes(parentNoteId)) { this.parents.push(parentNoteId); } @@ -451,7 +455,7 @@ class NoteShort { } for (const parentNote of this.getParentNotes()) { - if (parentNote.hasAncestor(ancestorNote)) {console.log(parentNote); + if (parentNote.hasAncestor(ancestorNote)) { return true; } } diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js index c1d42aa38..45f9919da 100644 --- a/src/public/app/widgets/note_tree.js +++ b/src/public/app/widgets/note_tree.js @@ -620,11 +620,11 @@ export default class NoteTreeWidget extends TabAwareWidget { /** * @param {Branch} branch */ - prepareNode(branch) { + prepareNode(branch, forceLazy = false) { const note = branch.getNoteFromCache(); if (!note) { - throw new Error(`Branch has no note "${branch.noteId}": ${JSON.stringify(branch)}`); + throw new Error(`Branch "${branch.branchId}" has no note "${branch.noteId}"`); } const title = (branch.prefix ? (branch.prefix + " - ") : "") + note.title; @@ -648,7 +648,7 @@ export default class NoteTreeWidget extends TabAwareWidget { key: utils.randomString(12) // this should prevent some "duplicate key" errors }; - if (isFolder && node.expanded) { + if (isFolder && node.expanded && !forceLazy) { node.children = this.prepareChildren(note); } @@ -984,7 +984,7 @@ export default class NoteTreeWidget extends TabAwareWidget { }, 600 * 1000); } - async entitiesReloadedEvent({loadResults}) { + async entitiesReloadedEvent({loadResults}) {console.log(loadResults); this.activityDetected(); if (loadResults.isEmptyForTree()) { @@ -1058,7 +1058,11 @@ export default class NoteTreeWidget extends TabAwareWidget { const found = (parentNode.getChildren() || []).find(child => child.data.noteId === branch.noteId); if (!found) { - parentNode.addChildren([await this.prepareNode(branch)]); + // make sure it's loaded + await treeCache.getNote(branch.noteId); + + // we're forcing lazy since it's not clear if the whole required subtree is in tree cache + parentNode.addChildren([this.prepareNode(branch, true)]); this.sortChildren(parentNode); }