mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-05-07 13:54:42 +02:00
#654 - Add the open on website action
This commit is contained in:
@@ -7,6 +7,7 @@ import { SlugAction } from './SlugAction';
|
||||
import { StartServerButton } from './StartServerButton';
|
||||
import * as l10n from '@vscode/l10n';
|
||||
import { LocalizationKey } from '../../localization';
|
||||
import { OpenOnWebsiteAction } from './Actions/OpenOnWebsiteAction';
|
||||
|
||||
export interface IActionsProps {
|
||||
metadata: any;
|
||||
@@ -28,6 +29,8 @@ const Actions: React.FunctionComponent<IActionsProps> = ({
|
||||
|
||||
{settings?.preview?.host && <Preview slug={metadata.slug} />}
|
||||
|
||||
<OpenOnWebsiteAction baseUrl={settings.websiteUrl} slug={metadata.slug} />
|
||||
|
||||
<StartServerButton settings={settings} />
|
||||
|
||||
{settings && settings.scripts && settings.scripts.length > 0 && (
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { messageHandler } from '@estruyf/vscode/dist/client';
|
||||
import * as React from 'react';
|
||||
import { ActionButton } from '../ActionButton';
|
||||
import * as l10n from "@vscode/l10n"
|
||||
import { LocalizationKey } from '../../../localization';
|
||||
import { GeneralCommands } from '../../../constants';
|
||||
|
||||
export interface IOpenOnWebsiteActionProps {
|
||||
baseUrl: string;
|
||||
slug: string;
|
||||
}
|
||||
|
||||
export const OpenOnWebsiteAction: React.FunctionComponent<IOpenOnWebsiteActionProps> = ({
|
||||
baseUrl,
|
||||
slug
|
||||
}: React.PropsWithChildren<IOpenOnWebsiteActionProps>) => {
|
||||
|
||||
const open = () => {
|
||||
messageHandler.send(GeneralCommands.toVSCode.openOnWebsite, {
|
||||
websiteUrl: baseUrl,
|
||||
});
|
||||
};
|
||||
|
||||
if (!baseUrl || !slug) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<ActionButton
|
||||
title={l10n.t(LocalizationKey.commonOpenOnWebsite)}
|
||||
onClick={open} />
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export * from './OpenOnWebsiteAction';
|
||||
Reference in New Issue
Block a user