diff --git a/apps/client/src/services/toast.ts b/apps/client/src/services/toast.ts index 09aa8454b..641b3cdce 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 3c9788943..9b2c03d4e 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> extends TypedComponent { @@ -56,9 +57,9 @@ export class TypedBasicWidget> 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> 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> 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> 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> extends TypedCompon getClosestNtxId() { if (this.$widget) { return this.$widget.closest("[data-ntx-id]").attr("data-ntx-id"); - } else { - return null; - } + } + return null; + } cleanup() {}