Skip to content

Commit

Permalink
#513 - devmode for ext
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Feb 28, 2023
1 parent 026bcd0 commit 8bc63a4
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/commands/Dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ export class Dashboard {
ViewColumn.One,
{
enableScripts: true,
retainContextWhenHidden: true
retainContextWhenHidden: true,
enableCommandUris: true
}
);

Expand Down
27 changes: 25 additions & 2 deletions src/dashboardWebView/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Messenger } from '@estruyf/vscode/dist/client';
import { TaxonomyView } from './TaxonomyView';
import { Route, Routes, useNavigate } from 'react-router-dom';
import { routePaths } from '..';
import { useEffect, useMemo } from 'react';
import { useEffect, useMemo, useState } from 'react';
import { UnknownView } from './UnknownView';
import { ErrorBoundary } from '@sentry/react';
import { ErrorView } from './ErrorView';
Expand All @@ -30,6 +30,7 @@ export const App: React.FunctionComponent<IAppProps> = ({
const { loading, pages, settings } = useMessages();
const view = useRecoilValue(DashboardViewSelector);
const mode = useRecoilValue(ModeAtom);
const [isDevMode, setIsDevMode] = useState(false);
const navigate = useNavigate();
useDarkMode();

Expand Down Expand Up @@ -60,6 +61,13 @@ export const App: React.FunctionComponent<IAppProps> = ({
navigate(routePaths[view]);
}, [view]);

useEffect(() => {
console.log(window.fmExternal)
if (window.fmExternal.isDevelopment) {
setIsDevMode(true);
}
}, []);

if (!settings) {
return <Spinner />;
}
Expand All @@ -86,6 +94,21 @@ Stack: ${componentStack}`
}}
>
<main className={`h-full w-full`}>
{
isDevMode && (
<div className="relative p-2 flex justify-center items-center bg-[var(--vscode-statusBar-debuggingBackground)] text-[var(--vscode-statusBar-debuggingForeground)]">
<span className='absolute left-2'>Development mode</span>

<a
className="ml-2 px-2 hover:text-[var(--vscode-statusBarItem-hoverForeground)] hover:bg-[var(--vscode-statusBarItem-hoverBackground)] hover:outline-none focus:outline-none"
href={`command:workbench.action.webview.reloadWebviewAction`}
title="Reload the dashboard">
Reload
</a>
</div>
)
}

<Routes>
<Route path={routePaths.welcome} element={<WelcomeScreen settings={settings} />} />
<Route
Expand All @@ -104,6 +127,6 @@ Stack: ${componentStack}`
<Route path={`*`} element={<UnknownView />} />
</Routes>
</main>
</ErrorBoundary>
</ErrorBoundary >
);
};
1 change: 1 addition & 0 deletions src/dashboardWebView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ declare const acquireVsCodeApi: <T = unknown>() => {
declare global {
interface Window {
fmExternal: {
isDevelopment: boolean;
getCustomFields: {
name: string,
html: (data: any, change: (value: any) => void) => Promise<CustomPanelViewResult | undefined>
Expand Down
22 changes: 22 additions & 0 deletions src/panelWebView/ViewPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import { FeatureFlag } from '../components/features/FeatureFlag';
import { FEATURE_FLAG } from '../constants/Features';
import { GitAction } from './components/Git/GitAction';
import { CustomView } from './components/CustomView';
import { useEffect, useState } from 'react';

export interface IViewPanelProps { }

export const ViewPanel: React.FunctionComponent<IViewPanelProps> = (
{ }: React.PropsWithChildren<IViewPanelProps>
) => {
const [isDevMode, setIsDevMode] = useState(false);
const {
loading,
mediaSelecting,
Expand All @@ -30,6 +32,13 @@ export const ViewPanel: React.FunctionComponent<IViewPanelProps> = (
mode
} = useMessages();

useEffect(() => {
console.log(window.fmExternal)
if (window.fmExternal.isDevelopment) {
setIsDevMode(true);
}
}, []);

if (mediaSelecting) {
return (
<div className="frontmatter media_selection">
Expand All @@ -48,6 +57,19 @@ export const ViewPanel: React.FunctionComponent<IViewPanelProps> = (

return (
<div className="frontmatter">
{
isDevMode && (
<div className="developer__bar">
<a
className="developer__bar__link"
href={`command:workbench.action.webview.reloadWebviewAction`}
title="Reload the dashboard">
Reload
</a>
</div>
)
}

<div className={`ext_actions`}>
<GitAction settings={settings} />

Expand Down
21 changes: 21 additions & 0 deletions src/panelWebView/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -1010,3 +1010,24 @@ vscode-divider {
.ql-snow .ql-toolbar .ql-picker-item.ql-selected .ql-stroke.ql-fill {
fill: var(--vscode-button-background) !important;
}

/* Extensibility Developer Bar */
.developer__bar {
background: var(--vscode-statusBar-debuggingBackground);
position: relative;
padding: 5px 15px;
display: flex;
align-items: center;
justify-content: center;

a {
color: var(--vscode-statusBar-debuggingForeground);

&:hover,
&:focus {
color: var(--vscode-statusBarItem-hoverForeground);
background: var(--vscode-statusBarItem-hoverBackground);
outline: none;
}
}
}

0 comments on commit 8bc63a4

Please sign in to comment.