mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
similar notes is getting updated automatically after the title change
This commit is contained in:
parent
9404e27cba
commit
2e05cb1764
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -374,7 +374,7 @@ ws.subscribeToOutsideSyncMessages(syncData => {
|
||||
|
||||
ws.subscribeToAllSyncMessages(syncData => {
|
||||
for (const tc of tabContexts) {
|
||||
tc.syncDataReceived(syncData);
|
||||
tc.eventReceived('syncData', syncData);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
@ -112,7 +112,7 @@ class StandardWidget {
|
||||
};
|
||||
}
|
||||
|
||||
syncDataReceived(syncData) {}
|
||||
eventReceived(name, data) {}
|
||||
|
||||
cleanup() {}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user