From 6ef1ba5b57f636a717aa26541758d642719cea3f Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Thu, 7 Apr 2022 16:24:31 +0200 Subject: [PATCH] Updated preview --- src/commands/Preview.ts | 106 +++++++++--------- src/constants/PreviewCommands.ts | 8 ++ src/constants/index.ts | 1 + .../components/Preview/Preview.tsx | 69 ++++++++++++ .../components/Preview/index.ts | 1 + src/dashboardWebView/index.tsx | 9 +- .../components/Icons/ToggleIcon.tsx | 2 +- 7 files changed, 143 insertions(+), 53 deletions(-) create mode 100644 src/constants/PreviewCommands.ts create mode 100644 src/dashboardWebView/components/Preview/Preview.tsx create mode 100644 src/dashboardWebView/components/Preview/index.ts diff --git a/src/commands/Preview.ts b/src/commands/Preview.ts index 90c063e3..8dc3298f 100644 --- a/src/commands/Preview.ts +++ b/src/commands/Preview.ts @@ -1,14 +1,15 @@ import { Telemetry } from './../helpers/Telemetry'; -import { SETTING_PREVIEW_HOST, SETTING_PREVIEW_PATHNAME, CONTEXT, TelemetryEvent } from './../constants'; +import { SETTING_PREVIEW_HOST, SETTING_PREVIEW_PATHNAME, CONTEXT, TelemetryEvent, PreviewCommands } from './../constants'; import { ArticleHelper } from './../helpers/ArticleHelper'; import { join } from "path"; import { commands, env, Uri, ViewColumn, window } from "vscode"; -import { Settings } from '../helpers'; +import { Extension, Settings } from '../helpers'; import { PreviewSettings } from '../models'; import { format } from 'date-fns'; import { DateHelper } from '../helpers/DateHelper'; import { Article } from '.'; import { urlJoin } from 'url-join-ts'; +import { WebviewHelper } from '@estruyf/vscode'; export class Preview { @@ -81,59 +82,62 @@ export class Preview { const cspSource = webView.webview.cspSource; - webView.webview.html = ` - - - - - -
- -
- + + ); +}; \ No newline at end of file diff --git a/src/dashboardWebView/components/Preview/index.ts b/src/dashboardWebView/components/Preview/index.ts new file mode 100644 index 00000000..7d1d8598 --- /dev/null +++ b/src/dashboardWebView/components/Preview/index.ts @@ -0,0 +1 @@ +export * from './Preview'; diff --git a/src/dashboardWebView/index.tsx b/src/dashboardWebView/index.tsx index bc5605d3..89803e6d 100644 --- a/src/dashboardWebView/index.tsx +++ b/src/dashboardWebView/index.tsx @@ -6,6 +6,7 @@ import * as Sentry from "@sentry/react"; import { Integrations } from "@sentry/tracing"; import { SENTRY_LINK } from "../constants"; import './styles.css'; +import { Preview } from "./components/Preview"; declare const acquireVsCodeApi: () => { getState: () => T; @@ -19,6 +20,8 @@ if (elm) { const version = elm?.getAttribute("data-version"); const environment = elm?.getAttribute("data-environment"); const isProd = elm?.getAttribute("data-isProd"); + const type = elm?.getAttribute("data-type"); + const url = elm?.getAttribute("data-url"); if (isProd === "true") { Sentry.init({ @@ -31,7 +34,11 @@ if (elm) { }); } - render(, elm); + if (type === "preview") { + render(, elm); + } else { + render(, elm); + } } // Webpack HMR diff --git a/src/panelWebView/components/Icons/ToggleIcon.tsx b/src/panelWebView/components/Icons/ToggleIcon.tsx index 87abe40e..7c4ad765 100644 --- a/src/panelWebView/components/Icons/ToggleIcon.tsx +++ b/src/panelWebView/components/Icons/ToggleIcon.tsx @@ -4,7 +4,7 @@ export interface IToggleIconProps {} export const ToggleIcon: React.FunctionComponent = (props: React.PropsWithChildren) => { return ( - +