From 1e94125133dbb10980b33ce87f2a3982e1671e02 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 20 Dec 2025 22:45:58 +0200 Subject: [PATCH] feat(client/bundle): display toast when parent is missing --- apps/client/src/services/bundle.ts | 4 ++-- apps/client/src/services/toast.ts | 14 +++++++++++++- apps/client/src/translations/en/translation.json | 3 ++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/apps/client/src/services/bundle.ts b/apps/client/src/services/bundle.ts index 7631cd316..9127705a3 100644 --- a/apps/client/src/services/bundle.ts +++ b/apps/client/src/services/bundle.ts @@ -6,7 +6,7 @@ import { WidgetDefinitionWithType } from "./frontend_script_api_preact.js"; import { t } from "./i18n.js"; import ScriptContext from "./script_context.js"; import server from "./server.js"; -import toastService from "./toast.js"; +import toastService, { showErrorForScriptNote } from "./toast.js"; import utils, { getErrorMessage } from "./utils.js"; // TODO: Deduplicate with server. @@ -86,7 +86,7 @@ export class WidgetsByParent { this.legacyWidgets[widget.parentWidget] = this.legacyWidgets[widget.parentWidget] || []; this.legacyWidgets[widget.parentWidget].push(widget); } else { - console.log(`Custom widget does not have mandatory 'parentWidget' property defined`); + showErrorForScriptNote(widget._noteId, t("toast.widget-missing-parent")); } } diff --git a/apps/client/src/services/toast.ts b/apps/client/src/services/toast.ts index 3e81bf6e1..4ab4f1efb 100644 --- a/apps/client/src/services/toast.ts +++ b/apps/client/src/services/toast.ts @@ -1,5 +1,6 @@ import { signal } from "@preact/signals"; +import froca from "./froca.js"; import utils from "./utils.js"; export interface ToastOptions { @@ -61,6 +62,17 @@ function showErrorTitleAndMessage(title: string, message: string, timeout = 1000 }); } +export async function showErrorForScriptNote(noteId: string, message: string) { + const note = await froca.getNote(noteId, true); + + addToast({ + title: note?.title ?? "", + icon: note?.getIcon() ?? "bx bx-error-circle", + message, + timeout: 15_000 + }); +} + //#region Toast store export const toasts = signal([]); @@ -74,7 +86,7 @@ function addToast(opts: ToastOptions) { function updateToast(id: string, partial: Partial) { toasts.value = toasts.value.map(toast => { if (toast.id === id) { - return { ...toast, ...partial } + return { ...toast, ...partial }; } return toast; }); diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json index df6d24dd4..648fe747a 100644 --- a/apps/client/src/translations/en/translation.json +++ b/apps/client/src/translations/en/translation.json @@ -28,7 +28,8 @@ }, "widget-render-error": { "title": "Failed to render a custom React widget" - } + }, + "widget-missing-parent": "Custom widget does not have mandatory 'parentWidget' property defined." }, "add_link": { "add_link": "Add link",