mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-07-06 01:41:48 +02:00
#647 - Fix open in browser
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { Messenger } from '@estruyf/vscode/dist/client';
|
||||
import { Messenger, messageHandler } from '@estruyf/vscode/dist/client';
|
||||
import { ArrowRightIcon, ExternalLinkIcon, RefreshIcon } from '@heroicons/react/outline';
|
||||
import * as React from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { PreviewCommands } from '../../../constants';
|
||||
import { GeneralCommands, PreviewCommands } from '../../../constants';
|
||||
import useThemeColors from '../../hooks/useThemeColors';
|
||||
import { EventData } from '@estruyf/vscode/dist/models';
|
||||
import * as l10n from '@vscode/l10n';
|
||||
@@ -18,6 +18,7 @@ export const Preview: React.FunctionComponent<IPreviewProps> = ({
|
||||
const iframeRef = useRef<HTMLIFrameElement>(null);
|
||||
const [crntUrl, setCrntUrl] = useState<string | null>(null);
|
||||
const { getColors } = useThemeColors();
|
||||
const [localeReady, setLocaleReady] = useState<boolean>(false);
|
||||
|
||||
const onRefresh = () => {
|
||||
if (iframeRef.current?.src) {
|
||||
@@ -51,6 +52,15 @@ export const Preview: React.FunctionComponent<IPreviewProps> = ({
|
||||
useEffect(() => {
|
||||
Messenger.listen(msgListener);
|
||||
|
||||
messageHandler.request<any>(GeneralCommands.toVSCode.getLocalization).then((data) => {
|
||||
if (data) {
|
||||
l10n.config({
|
||||
contents: data
|
||||
});
|
||||
}
|
||||
setLocaleReady(true);
|
||||
});
|
||||
|
||||
return () => {
|
||||
Messenger.unlisten(msgListener);
|
||||
};
|
||||
@@ -74,31 +84,35 @@ export const Preview: React.FunctionComponent<IPreviewProps> = ({
|
||||
className="w-full m-[1px] h-full border-1 border-transparent text-xs py-1 px-2 focus:border-color-blue-500 bg-[var(--vscode-tab-activeBackground)] text-[var(--vscode-tab-inactiveForeground)] hover:text-[var(--vscode-tab-activeForeground)] focus:text-[var(--vscode-tab-activeForeground)] placeholder-[var(--vscode-input-placeholderForeground)] focus:outline-[var(--vscode-focusBorder)] focus:outline-1 focus:outline-offset-0 focus:shadow-none focus:border-[var(--vscode-focusBorder)"
|
||||
/>
|
||||
|
||||
<div
|
||||
className={`actions flex items-center space-x-2 px-2 ${getColors('text-vulcan-500 dark:text-whisper-100', 'text-[var(--vscode-list-activeSelectionForeground)]')
|
||||
}`}
|
||||
>
|
||||
<button
|
||||
title={l10n.t(LocalizationKey.dashboardPreviewButtonOpenTitle)}
|
||||
onClick={navigateToUrl}
|
||||
className={getColors(`hover:text-vulcan-500 dark:hover:text-whisper-100`, `hover:text-[var(--vscode-textLink-activeForeground)]`)}>
|
||||
<ArrowRightIcon className="w-4 h-4" aria-hidden="true" />
|
||||
</button>
|
||||
{
|
||||
localeReady && (
|
||||
<div
|
||||
className={`actions flex items-center space-x-2 px-2 ${getColors('text-vulcan-500 dark:text-whisper-100', 'text-[var(--vscode-list-activeSelectionForeground)]')
|
||||
}`}
|
||||
>
|
||||
<button
|
||||
title={l10n.t(LocalizationKey.dashboardPreviewButtonOpenTitle)}
|
||||
onClick={navigateToUrl}
|
||||
className={getColors(`hover:text-vulcan-500 dark:hover:text-whisper-100`, `hover:text-[var(--vscode-textLink-activeForeground)]`)}>
|
||||
<ArrowRightIcon className="w-4 h-4" aria-hidden="true" />
|
||||
</button>
|
||||
|
||||
<button
|
||||
title={l10n.t(LocalizationKey.dashboardPreviewButtonRefreshTitle)}
|
||||
onClick={onRefresh}
|
||||
className={`mr-2 ${getColors(`hover:text-vulcan-500 dark:hover:text-whisper-100`, `hover:text-[var(--vscode-textLink-activeForeground)]`)}`}>
|
||||
<RefreshIcon className="w-4 h-4" aria-hidden="true" />
|
||||
</button>
|
||||
<button
|
||||
title={l10n.t(LocalizationKey.dashboardPreviewButtonRefreshTitle)}
|
||||
onClick={onRefresh}
|
||||
className={`mr-2 ${getColors(`hover:text-vulcan-500 dark:hover:text-whisper-100`, `hover:text-[var(--vscode-textLink-activeForeground)]`)}`}>
|
||||
<RefreshIcon className="w-4 h-4" aria-hidden="true" />
|
||||
</button>
|
||||
|
||||
<button
|
||||
title={l10n.t(LocalizationKey.dashboardPreviewButtonOpenTitle)}
|
||||
onClick={openInBrowser}
|
||||
className={`mr-2 ${getColors(`hover:text-vulcan-500 dark:hover:text-whisper-100`, `hover:text-[var(--vscode-textLink-activeForeground)]`)}`}>
|
||||
<ExternalLinkIcon className="w-4 h-4" aria-hidden="true" />
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
title={l10n.t(LocalizationKey.dashboardPreviewButtonOpenTitle)}
|
||||
onClick={openInBrowser}
|
||||
className={`mr-2 ${getColors(`hover:text-vulcan-500 dark:hover:text-whisper-100`, `hover:text-[var(--vscode-textLink-activeForeground)]`)}`}>
|
||||
<ExternalLinkIcon className="w-4 h-4" aria-hidden="true" />
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
|
||||
<iframe
|
||||
|
||||
Reference in New Issue
Block a user