Skip to content

Build your personal knowledge base with Trilium Notes

similar notes is getting updated automatically after the title change

zadam2e05cb176420
diff --git a/src/public/javascripts/services/attributes.js b/src/public/javascripts/services/attributes.js
index 36c6d95bf9..3146eec58f 100644
--- a/src/public/javascripts/services/attributes.js
+++ b/src/public/javascripts/services/attributes.js
@@ -267,9 +267,11 @@ class Attributes {
}
}
- syncDataReceived(syncData) {
- if (syncData.find(sd => sd.entityName === 'attributes' && sd.noteId === this.ctx.note.noteId)) {
- this.reloadAttributes();
+ eventReceived(name, data) {
+ if (name === 'syncData') {
+ if (data.find(sd => sd.entityName === 'attributes' && sd.noteId === this.ctx.note.noteId)) {
+ this.reloadAttributes();
+ }
}
}
}
diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js
index 2af5a19f78..cf2831d5c6 100644
--- a/src/public/javascripts/services/note_detail.js
+++ b/src/public/javascripts/services/note_detail.js
@@ -374,7 +374,7 @@ ws.subscribeToOutsideSyncMessages(syncData => {
ws.subscribeToAllSyncMessages(syncData => {
for (const tc of tabContexts) {
- tc.syncDataReceived(syncData);
+ tc.eventReceived('syncData', syncData);
}
});
diff --git a/src/public/javascripts/services/sidebar.js b/src/public/javascripts/services/sidebar.js
index bf1eee019a..7ade4ac1bb 100644
--- a/src/public/javascripts/services/sidebar.js
+++ b/src/public/javascripts/services/sidebar.js
@@ -106,10 +106,10 @@ class Sidebar {
}
}
- syncDataReceived(syncData) {
+ eventReceived(name, data) {
for (const widget of this.widgets) {
- if (widget.syncDataReceived) {
- widget.syncDataReceived(syncData);
+ if (widget.eventReceived) {
+ widget.eventReceived(name, data);
}
}
}
diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.js
index 4dc65af650..ddea635e13 100644
--- a/src/public/javascripts/services/tab_context.js
+++ b/src/public/javascripts/services/tab_context.js
@@ -267,6 +267,8 @@ class TabContext {
// run async
bundleService.executeRelationBundles(this.note, 'runOnNoteChange', this);
+
+ this.eventReceived('noteSaved');
}
async saveNoteIfChanged() {
@@ -366,11 +368,11 @@ class TabContext {
}
}
- syncDataReceived(syncData) {
- this.attributes.syncDataReceived(syncData);
+ eventReceived(name, data) {
+ this.attributes.eventReceived(name, data);
if (this.sidebar) {
- this.sidebar.syncDataReceived(syncData);
+ this.sidebar.eventReceived(name, data);
}
}
diff --git a/src/public/javascripts/widgets/attributes.js b/src/public/javascripts/widgets/attributes.js
index 3f800b19ae..f8a8be4771 100644
--- a/src/public/javascripts/widgets/attributes.js
+++ b/src/public/javascripts/widgets/attributes.js
@@ -81,11 +81,13 @@ class AttributesWidget extends StandardWidget {
}
}
- syncDataReceived(syncData) {
- if (syncData.find(sd => sd.entityName === 'attributes' && sd.noteId === this.ctx.note.noteId)) {
- // no need to invalidate attributes since the Attribute class listens to this as well
- // (and is guaranteed to run first)
- this.doRenderBody();
+ eventReceived(name, data) {
+ if (name === 'syncData') {
+ if (data.find(sd => sd.entityName === 'attributes' && sd.noteId === this.ctx.note.noteId)) {
+ // no need to invalidate attributes since the Attribute class listens to this as well
+ // (and is guaranteed to run first)
+ this.doRenderBody();
+ }
}
}
}
diff --git a/src/public/javascripts/widgets/link_map.js b/src/public/javascripts/widgets/link_map.js
index d3c7853479..2acd700f88 100644
--- a/src/public/javascripts/widgets/link_map.js
+++ b/src/public/javascripts/widgets/link_map.js
@@ -44,12 +44,14 @@ class LinkMapWidget extends StandardWidget {
}
}
- syncDataReceived(syncData) {
- if (syncData.find(sd => sd.entityName === 'attributes' && sd.noteId === this.ctx.note.noteId)) {
- // no need to invalidate attributes since the Attribute class listens to this as well
- // (and is guaranteed to run first)
- if (this.linkMapService) {
- this.linkMapService.loadNotesAndRelations();
+ eventReceived(name, data) {
+ if (name === 'syncData') {
+ if (data.find(sd => sd.entityName === 'attributes' && sd.noteId === this.ctx.note.noteId)) {
+ // no need to invalidate attributes since the Attribute class listens to this as well
+ // (and is guaranteed to run first)
+ if (this.linkMapService) {
+ this.linkMapService.loadNotesAndRelations();
+ }
}
}
}
diff --git a/src/public/javascripts/widgets/note_info.js b/src/public/javascripts/widgets/note_info.js
index ab89486114..281c8ae94b 100644
--- a/src/public/javascripts/widgets/note_info.js
+++ b/src/public/javascripts/widgets/note_info.js
@@ -45,9 +45,11 @@ class NoteInfoWidget extends StandardWidget {
$mime.text(note.mime);
}
- syncDataReceived(syncData) {
- if (syncData.find(sd => sd.entityName === 'notes' && sd.entityId === this.ctx.note.noteId)) {
- this.doRenderBody();
+ eventReceived(name, data) {
+ if (name === 'syncData') {
+ if (data.find(sd => sd.entityName === 'notes' && sd.entityId === this.ctx.note.noteId)) {
+ this.doRenderBody();
+ }
}
}
}
diff --git a/src/public/javascripts/widgets/note_revisions.js b/src/public/javascripts/widgets/note_revisions.js
index 9fa3e87189..fd1be98c62 100644
--- a/src/public/javascripts/widgets/note_revisions.js
+++ b/src/public/javascripts/widgets/note_revisions.js
@@ -41,9 +41,11 @@ class NoteRevisionsWidget extends StandardWidget {
}
}
- syncDataReceived(syncData) {
- if (syncData.find(sd => sd.entityName === 'note_revisions' && sd.noteId === this.ctx.note.noteId)) {
- this.doRenderBody();
+ eventReceived(name, data) {
+ if (name === 'syncData') {
+ if (data.find(sd => sd.entityName === 'note_revisions' && sd.noteId === this.ctx.note.noteId)) {
+ this.doRenderBody();
+ }
}
}
}
diff --git a/src/public/javascripts/widgets/similar_notes.js b/src/public/javascripts/widgets/similar_notes.js
index c8c08281ad..8da3d780b4 100644
--- a/src/public/javascripts/widgets/similar_notes.js
+++ b/src/public/javascripts/widgets/similar_notes.js
@@ -2,8 +2,6 @@ import StandardWidget from "./standard_widget.js";
import linkService from "../services/link.js";
import server from "../services/server.js";
import treeCache from "../services/tree_cache.js";
-import treeUtils from "../services/tree_utils.js";
-import treeService from "../services/tree.js";
class SimilarNotesWidget extends StandardWidget {
getWidgetTitle() { return "Similar notes"; }
@@ -11,6 +9,9 @@ class SimilarNotesWidget extends StandardWidget {
getMaxHeight() { return "200px"; }
async doRenderBody() {
+ // remember which title was when we found the similar notes
+ this.title = this.ctx.note.title;
+
const similarNotes = await server.get('similar_notes/' + this.ctx.note.noteId);
if (similarNotes.length === 0) {
@@ -39,6 +40,16 @@ class SimilarNotesWidget extends StandardWidget {
this.$body.empty().append($list);
}
+
+ eventReceived(name, data) {
+ if (name === 'noteSaved') {
+ if (this.title !== this.ctx.note.title) {
+ this.rendered = false;
+
+ this.renderBody();
+ }
+ }
+ }
}
export default SimilarNotesWidget;
\ No newline at end of file
diff --git a/src/public/javascripts/widgets/standard_widget.js b/src/public/javascripts/widgets/standard_widget.js
index dcd7e9d6bb..a5596e2c49 100644
--- a/src/public/javascripts/widgets/standard_widget.js
+++ b/src/public/javascripts/widgets/standard_widget.js
@@ -112,7 +112,7 @@ class StandardWidget {
};
}
- syncDataReceived(syncData) {}
+ eventReceived(name, data) {}
cleanup() {}
}