fix creating new note

This commit is contained in:
zadam 2020-08-28 14:29:20 +02:00
parent 30e84321f9
commit 9873dd1242
2 changed files with 14 additions and 6 deletions

View File

@ -56,6 +56,10 @@ class NoteShort {
} }
addParent(parentNoteId, branchId) { addParent(parentNoteId, branchId) {
if (parentNoteId === 'none') {
return;
}
if (!this.parents.includes(parentNoteId)) { if (!this.parents.includes(parentNoteId)) {
this.parents.push(parentNoteId); this.parents.push(parentNoteId);
} }
@ -451,7 +455,7 @@ class NoteShort {
} }
for (const parentNote of this.getParentNotes()) { for (const parentNote of this.getParentNotes()) {
if (parentNote.hasAncestor(ancestorNote)) {console.log(parentNote); if (parentNote.hasAncestor(ancestorNote)) {
return true; return true;
} }
} }

View File

@ -620,11 +620,11 @@ export default class NoteTreeWidget extends TabAwareWidget {
/** /**
* @param {Branch} branch * @param {Branch} branch
*/ */
prepareNode(branch) { prepareNode(branch, forceLazy = false) {
const note = branch.getNoteFromCache(); const note = branch.getNoteFromCache();
if (!note) { 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; 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 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); node.children = this.prepareChildren(note);
} }
@ -984,7 +984,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
}, 600 * 1000); }, 600 * 1000);
} }
async entitiesReloadedEvent({loadResults}) { async entitiesReloadedEvent({loadResults}) {console.log(loadResults);
this.activityDetected(); this.activityDetected();
if (loadResults.isEmptyForTree()) { if (loadResults.isEmptyForTree()) {
@ -1058,7 +1058,11 @@ export default class NoteTreeWidget extends TabAwareWidget {
const found = (parentNode.getChildren() || []).find(child => child.data.noteId === branch.noteId); const found = (parentNode.getChildren() || []).find(child => child.data.noteId === branch.noteId);
if (!found) { 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); this.sortChildren(parentNode);
} }