mirror of
https://github.com/zadam/trilium.git
synced 2025-12-22 23:34:25 +01:00
feat(client/bundle): display toast when parent is missing
This commit is contained in:
parent
64a770175f
commit
1e94125133
@ -6,7 +6,7 @@ import { WidgetDefinitionWithType } from "./frontend_script_api_preact.js";
|
|||||||
import { t } from "./i18n.js";
|
import { t } from "./i18n.js";
|
||||||
import ScriptContext from "./script_context.js";
|
import ScriptContext from "./script_context.js";
|
||||||
import server from "./server.js";
|
import server from "./server.js";
|
||||||
import toastService from "./toast.js";
|
import toastService, { showErrorForScriptNote } from "./toast.js";
|
||||||
import utils, { getErrorMessage } from "./utils.js";
|
import utils, { getErrorMessage } from "./utils.js";
|
||||||
|
|
||||||
// TODO: Deduplicate with server.
|
// TODO: Deduplicate with server.
|
||||||
@ -86,7 +86,7 @@ export class WidgetsByParent {
|
|||||||
this.legacyWidgets[widget.parentWidget] = this.legacyWidgets[widget.parentWidget] || [];
|
this.legacyWidgets[widget.parentWidget] = this.legacyWidgets[widget.parentWidget] || [];
|
||||||
this.legacyWidgets[widget.parentWidget].push(widget);
|
this.legacyWidgets[widget.parentWidget].push(widget);
|
||||||
} else {
|
} else {
|
||||||
console.log(`Custom widget does not have mandatory 'parentWidget' property defined`);
|
showErrorForScriptNote(widget._noteId, t("toast.widget-missing-parent"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { signal } from "@preact/signals";
|
import { signal } from "@preact/signals";
|
||||||
|
|
||||||
|
import froca from "./froca.js";
|
||||||
import utils from "./utils.js";
|
import utils from "./utils.js";
|
||||||
|
|
||||||
export interface ToastOptions {
|
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
|
//#region Toast store
|
||||||
export const toasts = signal<ToastOptionsWithRequiredId[]>([]);
|
export const toasts = signal<ToastOptionsWithRequiredId[]>([]);
|
||||||
|
|
||||||
@ -74,7 +86,7 @@ function addToast(opts: ToastOptions) {
|
|||||||
function updateToast(id: string, partial: Partial<ToastOptions>) {
|
function updateToast(id: string, partial: Partial<ToastOptions>) {
|
||||||
toasts.value = toasts.value.map(toast => {
|
toasts.value = toasts.value.map(toast => {
|
||||||
if (toast.id === id) {
|
if (toast.id === id) {
|
||||||
return { ...toast, ...partial }
|
return { ...toast, ...partial };
|
||||||
}
|
}
|
||||||
return toast;
|
return toast;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -28,7 +28,8 @@
|
|||||||
},
|
},
|
||||||
"widget-render-error": {
|
"widget-render-error": {
|
||||||
"title": "Failed to render a custom React widget"
|
"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": "Add link",
|
"add_link": "Add link",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user