diff --git a/src/public/javascripts/services/tree_cache.js b/src/public/javascripts/services/tree_cache.js index 61604fbad..a56688d8d 100644 --- a/src/public/javascripts/services/tree_cache.js +++ b/src/public/javascripts/services/tree_cache.js @@ -123,7 +123,7 @@ class TreeCache { } } - async reloadNotes(noteIds) { + async reloadData(noteIds) { const resp = await server.post('tree/load', { noteIds }); this.addResp(resp.notes, resp.branches, resp.attributes); @@ -224,6 +224,36 @@ class TreeCache { return child.parentToBranch[parentNoteId]; } + + syncDataListener({data}) {return; + const noteIdsToRefresh = new Set(); + + data.filter(sync => sync.entityName === 'branches').forEach(sync => { + const branch = this.branches[sync.entityId]; + // we assume that the cache contains the old branch state and we add also the old parentNoteId + // so that the old parent can also be updated + noteIdsToRefresh.add(branch.parentNoteId); + + // this should then contain new parentNoteId for which we should also update the cache + noteIdsToRefresh.add(sync.parentNoteId); + }); + + data.filter(sync => sync.entityName === 'notes').forEach(sync => noteIdsToRefresh.add(sync.entityId)); + + data.filter(sync => sync.entityName === 'note_reordering').forEach(sync => noteIdsToRefresh.add(sync.entityId)); + + data.filter(sync => sync.entityName === 'attributes').forEach(sync => { + const note = treeCache.notes[sync.noteId]; + + if (note && note.__attributeCache) { + noteIdsToRefresh.add(sync.entityId); + } + }); + + if (noteIdsToRefresh.size > 0) { + this.reloadNotes({noteIds: Array.from(noteIdsToRefresh)}); + } + } } const treeCache = new TreeCache(); diff --git a/src/public/javascripts/widgets/attributes.js b/src/public/javascripts/widgets/attributes.js index fad0351a0..cab4d6ad0 100644 --- a/src/public/javascripts/widgets/attributes.js +++ b/src/public/javascripts/widgets/attributes.js @@ -88,12 +88,6 @@ class AttributesWidget extends StandardWidget { } } - toggle(show) { - console.trace("attributes toggle", show); - - super.toggle(show); - } - syncDataListener({data}) { if (data.find(sd => sd.entityName === 'attributes' && sd.noteId === this.tabContext.note.noteId)) { // no need to invalidate attributes since the Attribute class listens to this as well diff --git a/src/public/javascripts/widgets/note_tree.js b/src/public/javascripts/widgets/note_tree.js index 526d5facb..195207e0f 100644 --- a/src/public/javascripts/widgets/note_tree.js +++ b/src/public/javascripts/widgets/note_tree.js @@ -533,7 +533,7 @@ export default class NoteTreeWidget extends TabAwareWidget { } } - syncDataListener({data}) { + syncDataListener({data}) {return; const noteIdsToRefresh = new Set(); // this has the problem that the former parentNoteId might not be invalidated