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

This commit is contained in:
Elian Doran 2025-12-20 23:34:36 +02:00
parent 2c25786fa2
commit f8bf301d12
No known key found for this signature in database
2 changed files with 17 additions and 20 deletions

View File

@ -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,

View File

@ -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", {
showErrorForScriptNote(noteId, t("toast.widget-error.message-custom", {
id: noteId,
title: note?.title,
message: e.message || e.toString()
})
});
}));
});
} else {
toastService.showPersistent({
@ -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() {}