diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json index 9f33fd8c35..01d69ec156 100644 --- a/apps/client/src/translations/en/translation.json +++ b/apps/client/src/translations/en/translation.json @@ -1070,10 +1070,12 @@ "note_detail_render_help_1": "This help note is shown because this note of type Render HTML doesn't have required relation to function properly.", "note_detail_render_help_2": "Render HTML note type is used for scripting. In short, you have a HTML code note (optionally with some JavaScript) and this note will render it. To make it work, you need to define a relation called \"renderNote\" pointing to the HTML note to render." }, - "web_view": { - "web_view": "Web View", - "embed_websites": "Note of type Web View allows you to embed websites into Trilium.", - "create_label": "To start, please create a label with a URL address you want to embed, e.g. #webViewSrc=\"https://www.google.com\"" + "web_view_setup": { + "title": "Create a live view of a webpage directly into Trilium", + "url_placeholder": "Enter or paste the website address, for example https://triliumnotes.org", + "create_button": "Create Web View", + "invalid_url_title": "Invalid address", + "invalid_url_message": "Insert a valid web address, for example https://triliumnotes.org." }, "backend_log": { "refresh": "Refresh" diff --git a/apps/client/src/widgets/type_widgets/WebView.css b/apps/client/src/widgets/type_widgets/WebView.css index 42ac871cfb..c158e3ceae 100644 --- a/apps/client/src/widgets/type_widgets/WebView.css +++ b/apps/client/src/widgets/type_widgets/WebView.css @@ -16,3 +16,20 @@ width: 100%; height: 100%; } + +.web-view-setup-form { + height: 100%; + display: flex; + flex-direction: column; + justify-content: center; + padding-inline: 40px; + + .form-icon { + margin-bottom: 12px; + } + + .form-group { + width: 100%; + max-width: 600px; + } +} \ No newline at end of file diff --git a/apps/client/src/widgets/type_widgets/WebView.tsx b/apps/client/src/widgets/type_widgets/WebView.tsx index c91634b02a..405ae93a43 100644 --- a/apps/client/src/widgets/type_widgets/WebView.tsx +++ b/apps/client/src/widgets/type_widgets/WebView.tsx @@ -1,9 +1,13 @@ +import { useCallback, useState } from "preact/hooks"; +import FNote from "../../entities/fnote"; import { t } from "../../services/i18n"; import utils from "../../services/utils"; -import Alert from "../react/Alert"; import { useNoteLabel } from "../react/hooks"; import { TypeWidgetProps } from "./type_widget"; import "./WebView.css"; +import FormGroup from "../react/FormGroup"; +import toast from "../../services/toast"; +import Button from "../react/Button"; const isElectron = utils.isElectron(); @@ -12,7 +16,7 @@ export default function WebView({ note }: TypeWidgetProps) { return (webViewSrc ? - : + : ); } @@ -24,12 +28,41 @@ function WebViewContent({ src }: { src: string }) { } } -function WebViewHelp() { - return ( - -

{t("web_view.web_view")}

-

{t("web_view.embed_websites")}

-

{t("web_view.create_label")}

-
- ) +function SetupWebView({note}: {note: FNote}) { + const [srcLabel, setSrcLabel] = useNoteLabel(note, "webViewSrc"); + const [src, setSrc] = useState(""); + + const submit = useCallback((url: string) => { + try { + // Validate URL + new URL(url); + } catch (ex) { + toast.showErrorTitleAndMessage(t("web_view_setup.invalid_url_title"), + t("web_view_setup.invalid_url_message")); + return; + } + + setSrcLabel(url); + }, [note]); + + return
+
submit(src)}> + + + + {setSrc((e.target as HTMLInputElement)?.value)}} + /> + + +
}