Skip to content

Build your personal knowledge base with Trilium Notes

chore(react/type_widget): pass error information

Elian Doran695e8489ad21
diff --git a/apps/client/src/widgets/react/Admonition.tsx b/apps/client/src/widgets/react/Admonition.tsx
index d5de3a5c86..5fb86daf2a 100644
--- a/apps/client/src/widgets/react/Admonition.tsx
+++ b/apps/client/src/widgets/react/Admonition.tsx
@@ -3,12 +3,13 @@ import { ComponentChildren } from "preact";
interface AdmonitionProps {
type: "warning" | "note" | "caution";
children: ComponentChildren;
+ className?: string;
}
-export default function Admonition({ type, children }: AdmonitionProps) {
+export default function Admonition({ type, children, className }: AdmonitionProps) {
return (
- <div className={`admonition ${type}`} role="alert">
+ <div className={`admonition ${type} ${className}`} role="alert">
{children}
</div>
)
-}
\ No newline at end of file
+}
diff --git a/apps/client/src/widgets/type_widgets/helpers/SplitEditor.tsx b/apps/client/src/widgets/type_widgets/helpers/SplitEditor.tsx
index f2554d9e17..33a0d4768b 100644
--- a/apps/client/src/widgets/type_widgets/helpers/SplitEditor.tsx
+++ b/apps/client/src/widgets/type_widgets/helpers/SplitEditor.tsx
@@ -1,8 +1,13 @@
import { isMobile } from "../../../services/utils";
-import { useNoteLabel, useNoteLabelBoolean, useTriliumOption } from "../../react/hooks";
+import Admonition from "../../react/Admonition";
+import { useNoteLabelBoolean, useTriliumOption } from "../../react/hooks";
import { TypeWidgetProps } from "../type_widget";
import "./SplitEditor.css";
+interface SplitEditorProps extends TypeWidgetProps {
+ error?: string | null;
+}
+
/**
* Abstract `TypeWidget` which contains a preview and editor pane, each displayed on half of the available screen.
*
@@ -12,19 +17,21 @@ import "./SplitEditor.css";
* - Can display errors to the user via {@link setError}.
* - Horizontal or vertical orientation for the editor/preview split, adjustable via the switch split orientation button floating button.
*/
-export default function SplitEditor({ note }: TypeWidgetProps) {
+export default function SplitEditor({ note, error }: SplitEditorProps) {
const splitEditorOrientation = useSplitOrientation();
const [ readOnly ] = useNoteLabelBoolean(note, "readOnly");
const editor = (!readOnly &&
<div className="note-detail-split-editor-col">
<div className="note-detail-split-editor">Detail goes here.</div>
- <div className="admonition caution note-detail-error-container hidden-ext">Errors go here.</div>
+ {error && <Admonition type="caution" className="note-detail-error-container">
+ {error}
+ </Admonition>}
</div>
);
const preview = (
- <div className="note-detail-split-preview-col">
+ <div className={`note-detail-split-preview-col ${error ? "on-error" : ""}`}>
<div className="note-detail-split-preview">Preview goes here</div>
<div className="btn-group btn-group-sm map-type-switcher content-floating-buttons preview-buttons bottom-right" role="group">Buttons go here</div>
</div>
diff --git a/apps/client/src/widgets/type_widgets/helpers/SvgSplitEditor.tsx b/apps/client/src/widgets/type_widgets/helpers/SvgSplitEditor.tsx
index 60a1c2e2fa..88fb36704f 100644
--- a/apps/client/src/widgets/type_widgets/helpers/SvgSplitEditor.tsx
+++ b/apps/client/src/widgets/type_widgets/helpers/SvgSplitEditor.tsx
@@ -3,6 +3,9 @@ import SplitEditor from "./SplitEditor";
export default function SvgSplitEditor(props: TypeWidgetProps) {
return (
- <SplitEditor {...props} />
+ <SplitEditor
+ error="Hi there"
+ {...props}
+ />
)
}
diff --git a/apps/client/src/widgets/type_widgets_old/abstract_split_type_widget.ts b/apps/client/src/widgets/type_widgets_old/abstract_split_type_widget.ts
index 5234f00376..3085d2d19c 100644
--- a/apps/client/src/widgets/type_widgets_old/abstract_split_type_widget.ts
+++ b/apps/client/src/widgets/type_widgets_old/abstract_split_type_widget.ts
@@ -143,12 +143,6 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget {
return [];
}
- setError(message: string | null | undefined) {
- this.$errorContainer.toggleClass("hidden-ext", !message);
- this.$preview.toggleClass("on-error", !!message);
- this.$errorContainer.text(message ?? "");
- }
-
getData() {
return this.editorTypeWidget.getData();
}