Skip to content

Build your personal knowledge base with Trilium Notes

feat(client/bundle): use new toast for script errors with known note ID

Elian Doranf8bf301d12e3
diff --git a/apps/client/src/services/toast.ts b/apps/client/src/services/toast.ts
index 09aa8454b0..641b3cdcee 100644
--- a/apps/client/src/services/toast.ts
+++ b/apps/client/src/services/toast.ts
@@ -67,7 +67,8 @@ function showErrorTitleAndMessage(title: string, message: string, timeout = 1000
export async function showErrorForScriptNote(noteId: string, message: string) {
const note = await froca.getNote(noteId, true);
- addToast({
+ showPersistent({
+ id: `custom-widget-failure-${noteId}`,
title: note?.title ?? "",
icon: note?.getIcon() ?? "bx bx-error-circle",
message,
diff --git a/apps/client/src/widgets/basic_widget.ts b/apps/client/src/widgets/basic_widget.ts
index 3c97889437..9b2c03d4ec 100644
--- a/apps/client/src/widgets/basic_widget.ts
+++ b/apps/client/src/widgets/basic_widget.ts
@@ -1,8 +1,9 @@
import { isValidElement, VNode } from "preact";
+
import Component, { TypedComponent } from "../components/component.js";
import froca from "../services/froca.js";
import { t } from "../services/i18n.js";
-import toastService from "../services/toast.js";
+import toastService, { showErrorForScriptNote } from "../services/toast.js";
import { renderReactWidget } from "./react/react_utils.jsx";
export class TypedBasicWidget<T extends TypedComponent<any>> extends TypedComponent<T> {
@@ -56,9 +57,9 @@ export class TypedBasicWidget<T extends TypedComponent<any>> extends TypedCompon
optChild(condition: boolean, ...components: (T | VNode)[]) {
if (condition) {
return this.child(...components);
- } else {
- return this;
- }
+ }
+ return this;
+
}
id(id: string) {
@@ -172,16 +173,11 @@ export class TypedBasicWidget<T extends TypedComponent<any>> extends TypedCompon
const noteId = this._noteId;
if (this._noteId) {
froca.getNote(noteId, true).then((note) => {
- toastService.showPersistent({
- id: `custom-widget-failure-${noteId}`,
- title: t("toast.widget-error.title"),
- icon: "bx bx-error-circle",
- message: t("toast.widget-error.message-custom", {
- id: noteId,
- title: note?.title,
- message: e.message || e.toString()
- })
- });
+ showErrorForScriptNote(noteId, t("toast.widget-error.message-custom", {
+ id: noteId,
+ title: note?.title,
+ message: e.message || e.toString()
+ }));
});
} else {
toastService.showPersistent({
@@ -213,7 +209,7 @@ export class TypedBasicWidget<T extends TypedComponent<any>> extends TypedCompon
toggleInt(show: boolean | null | undefined) {
this.$widget.toggleClass("hidden-int", !show)
- .toggleClass("visible", !!show);
+ .toggleClass("visible", !!show);
}
isHiddenInt() {
@@ -222,7 +218,7 @@ export class TypedBasicWidget<T extends TypedComponent<any>> extends TypedCompon
toggleExt(show: boolean | null | "" | undefined) {
this.$widget.toggleClass("hidden-ext", !show)
- .toggleClass("visible", !!show);
+ .toggleClass("visible", !!show);
}
isHiddenExt() {
@@ -250,9 +246,9 @@ export class TypedBasicWidget<T extends TypedComponent<any>> extends TypedCompon
getClosestNtxId() {
if (this.$widget) {
return this.$widget.closest("[data-ntx-id]").attr("data-ntx-id");
- } else {
- return null;
- }
+ }
+ return null;
+
}
cleanup() {}