Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
wip
zadam9301679707d6
diff --git a/src/public/javascripts/services/load_results.js b/src/public/javascripts/services/load_results.jsnew file mode 100644index 0000000000..ef0053194b--- /dev/null+++ b/src/public/javascripts/services/load_results.js@@ -0,0 +1,29 @@+export class LoadResults {+ constructor() {+ this.noteIdToSync = {};+ this.sourceIdToNoteIds = {};+ }++ add(noteId, sourceId) {+ this.noteIdToSync[noteId] = this.noteIdToSync[noteId] || [];++ if (!this.noteIdToSync[noteId].includes(sourceId)) {+ this.noteIdToSync[noteId].push(sourceId);+ }++ this.sourceIdToNoteIds[sourceId] = this.sourceIdToNoteIds[sourceId] || [];++ if (!this.sourceIdToNoteIds[sourceId]) {+ this.sourceIdToNoteIds[sourceId].push(noteId);+ }+ }++ getNoteIds() {+ return Object.keys(this.noteIdToSync);+ }++ isNoteReloaded(noteId, sourceId) {+ const sourceIds = this.noteIdToSync[noteId];+ return sourceIds && !!sourceIds.find(sId => sId !== sourceId);+ }+}\ No newline at end of filediff --git a/src/public/javascripts/services/tree_cache.js b/src/public/javascripts/services/tree_cache.jsindex d88cb20253..8586506a58 100644--- a/src/public/javascripts/services/tree_cache.js+++ b/src/public/javascripts/services/tree_cache.js@@ -2,6 +2,7 @@ import Branch from "../entities/branch.js";import NoteShort from "../entities/note_short.js";import Attribute from "../entities/attribute.js";import server from "./server.js";+import {LoadResults} from "./load_results.js";/*** TreeCache keeps a read only cache of note tree structure in frontend's memory.@@ -158,9 +159,6 @@ class TreeCache {this.addResp([note], branches, []);}}-- const appContext = (await import('./app_context.js')).default;- appContext.trigger('notesReloaded', {noteIds})}/** @return {Promise<NoteShort[]>} */@@ -231,26 +229,31 @@ class TreeCache {}async processSyncRows(syncRows) {- const noteIdsToRefresh = new Set();+ const loadResults = new LoadResults();syncRows.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);+ loadResults.add(branch.parentNoteId, sync.sourceId);// this should then contain new parentNoteId for which we should also update the cache- noteIdsToRefresh.add(sync.parentNoteId);+ loadResults.add(sync.parentNoteId, sync.sourceId);++ loadResults.add(sync.noteId, sync.sourceId);});- syncRows.filter(sync => sync.entityName === 'notes').forEach(sync => noteIdsToRefresh.add(sync.entityId));+ syncRows.filter(sync => sync.entityName === 'notes').forEach(sync => loadResults.add(sync.entityId, sync.sourceId));- syncRows.filter(sync => sync.entityName === 'note_reordering').forEach(sync => noteIdsToRefresh.add(sync.entityId));+ syncRows.filter(sync => sync.entityName === 'note_reordering').forEach(sync => loadResults.add(sync.entityId, sync.sourceId));// missing reloading the relation target note- syncRows.filter(sync => sync.entityName === 'attributes').forEach(sync => noteIdsToRefresh.add(sync.noteId));+ syncRows.filter(sync => sync.entityName === 'attributes').forEach(sync => loadResults.add(sync.noteId, sync.sourceId));- await this.reloadNotes(Array.from(noteIdsToRefresh));+ await this.reloadNotes(loadResults.getNoteIds());++ const appContext = (await import('./app_context.js')).default;+ appContext.trigger('notesReloaded', {loadResults});}}diff --git a/src/public/javascripts/widgets/note_detail.js b/src/public/javascripts/widgets/note_detail.jsindex 1b0eacf9bb..023379f566 100644--- a/src/public/javascripts/widgets/note_detail.js+++ b/src/public/javascripts/widgets/note_detail.js@@ -219,4 +219,10 @@ export default class NoteDetailWidget extends TabAwareWidget {protectedSessionStartedListener() {this.refresh();}++ notesReloadedListener({loadResults}) {+ if (loadResults.isNoteReloaded(this.noteId, this.componentId)) {+ this.refresh();+ }+ }}\ No newline at end of filediff --git a/src/public/javascripts/widgets/tab_aware_widget.js b/src/public/javascripts/widgets/tab_aware_widget.jsindex d621eccb66..6bba19c588 100644--- a/src/public/javascripts/widgets/tab_aware_widget.js+++ b/src/public/javascripts/widgets/tab_aware_widget.js@@ -13,7 +13,15 @@ export default class TabAwareWidget extends BasicWidget {}isNote(noteId) {- return this.tabContext && this.tabContext.note && this.tabContext.note.noteId === noteId;+ return this.noteId === noteId;+ }++ get note() {+ return this.tabContext && this.tabContext.note;+ }++ get noteId() {+ return this.note && this.note.noteId;}tabNoteSwitchedListener({tabId}) {