Skip to content

Build your personal knowledge base with Trilium Notes

add API method to force refresh of included notes, closes #1106

zadam16fef7834451
diff --git a/src/public/app/services/frontend_script_api.js b/src/public/app/services/frontend_script_api.js
index 3b8c37a56c..b557eae41d 100644
--- a/src/public/app/services/frontend_script_api.js
+++ b/src/public/app/services/frontend_script_api.js
@@ -403,6 +403,13 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
* @method
*/
this.waitUntilSynced = ws.waitForMaxKnownSyncId;
+
+ /**
+ * This will refresh all currently opened notes which have included note specified in the parameter
+ *
+ * @param includedNoteId - noteId of the included note
+ */
+ this.refreshIncludedNote = includedNoteId => appContext.triggerEvent('refreshIncludedNote', {noteId: includedNoteId});
}
-export default FrontendScriptApi;
\ No newline at end of file
+export default FrontendScriptApi;
diff --git a/src/public/app/widgets/type_widgets/abstract_text_type_widget.js b/src/public/app/widgets/type_widgets/abstract_text_type_widget.js
index 43099b9520..54f44ccfb1 100644
--- a/src/public/app/widgets/type_widgets/abstract_text_type_widget.js
+++ b/src/public/app/widgets/type_widgets/abstract_text_type_widget.js
@@ -62,4 +62,12 @@ export default class AbstractTextTypeWidget extends TypeWidget {
$el.text(title);
}
-}
\ No newline at end of file
+
+ refreshIncludedNote($container, noteId) {
+ if ($container) {
+ $container.find(`section[data-note-id="${noteId}"]`).each((_, el) => {
+ this.loadIncludedNote(noteId, $(el));
+ });
+ }
+ }
+}
diff --git a/src/public/app/widgets/type_widgets/editable_text.js b/src/public/app/widgets/type_widgets/editable_text.js
index cb5ab2737d..1a4f8a1e00 100644
--- a/src/public/app/widgets/type_widgets/editable_text.js
+++ b/src/public/app/widgets/type_widgets/editable_text.js
@@ -257,4 +257,8 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
this.textEditor.model.insertContent(imageElement, this.textEditor.model.document.selection);
} );
}
+
+ async refreshIncludedNoteEvent({noteId}) {
+ this.refreshIncludedNote(this.$editor, noteId);
+ }
}
diff --git a/src/public/app/widgets/type_widgets/read_only_text.js b/src/public/app/widgets/type_widgets/read_only_text.js
index 9e76414146..21a37c0160 100644
--- a/src/public/app/widgets/type_widgets/read_only_text.js
+++ b/src/public/app/widgets/type_widgets/read_only_text.js
@@ -81,4 +81,8 @@ export default class ReadOnlyTextTypeWidget extends AbstractTextTypeWidget {
this.loadIncludedNote(noteId, $(el));
});
}
+
+ async refreshIncludedNoteEvent({noteId}) {
+ this.refreshIncludedNote(this.$content, noteId);
+ }
}