note title widget and protected session entering fixes

This commit is contained in:
zadam
2020-05-03 22:49:20 +02:00
parent 647790885d
commit 8b5536ee3a
5 changed files with 30 additions and 25 deletions

View File

@@ -20,6 +20,8 @@ class TreeCache {
async loadInitialTree() {
const resp = await server.get('tree');
await this.loadParents(resp, false);
// clear the cache only directly before adding new content which is important for e.g. switching to protected session
/** @type {Object.<string, NoteShort>} */
@@ -34,22 +36,22 @@ class TreeCache {
/** @type {Object.<string, Promise<NoteComplement>>} */
this.noteComplementPromises = {};
await this.loadParents(resp);
this.addResp(resp);
}
async loadParents(resp) {
async loadParents(resp, additiveLoad) {
const noteIds = new Set(resp.notes.map(note => note.noteId));
const missingNoteIds = [];
const existingNotes = additiveLoad ? this.notes : {};
for (const branch of resp.branches) {
if (!(branch.parentNoteId in this.notes) && !noteIds.has(branch.parentNoteId) && branch.parentNoteId !== 'none') {
if (!(branch.parentNoteId in existingNotes) && !noteIds.has(branch.parentNoteId) && branch.parentNoteId !== 'none') {
missingNoteIds.push(branch.parentNoteId);
}
}
for (const attr of resp.attributes) {
if (attr.type === 'relation' && attr.name === 'template' && !(attr.value in this.notes) && !noteIds.has(attr.value)) {
if (attr.type === 'relation' && attr.name === 'template' && !(attr.value in existingNotes) && !noteIds.has(attr.value)) {
missingNoteIds.push(attr.value);
}
}
@@ -61,7 +63,7 @@ class TreeCache {
resp.branches = resp.branches.concat(newResp.branches);
resp.attributes = resp.attributes.concat(newResp.attributes);
await this.loadParents(resp);
await this.loadParents(resp, additiveLoad);
}
}
@@ -154,7 +156,7 @@ class TreeCache {
const resp = await server.post('tree/load', { noteIds });
await this.loadParents(resp);
await this.loadParents(resp, true);
this.addResp(resp);
for (const note of resp.notes) {