diff --git a/src/editor/ReactWebView.ts b/src/editor/ReactWebView.ts index f8e06f73..91f0d58f 100644 --- a/src/editor/ReactWebView.ts +++ b/src/editor/ReactWebView.ts @@ -1,6 +1,6 @@ -import * as vscode from 'vscode' -import * as CR from 'typings' import * as path from 'path' +import * as CR from 'typings' +import * as vscode from 'vscode' /** * Manages React webview panels @@ -71,7 +71,7 @@ class ReactWebView { if (callback) { // listen for when webview is loaded // unfortunately there is no easy way of doing this - let webPanelListener = setInterval(() => { + const webPanelListener = setInterval(() => { if (this.loaded) { setTimeout(callback) clearInterval(webPanelListener) @@ -80,6 +80,27 @@ class ReactWebView { } } + public async postMessage(action: CR.Action): Promise { + // Send a message to the webview webview. + // You can send any JSON serializable data. + const success = await this.panel.webview.postMessage(action) + if (!success) { + throw new Error(`Message post failure: ${JSON.stringify(action)}`) + } + } + + public dispose(): void { + // Clean up our resources + this.panel.dispose() + + while (this.disposables.length) { + const x = this.disposables.pop() + if (x) { + x.dispose() + } + } + } + private createWebviewPanel(column: number): vscode.WebviewPanel { const viewType = 'CodeRoad' const title = 'CodeRoad' @@ -103,27 +124,6 @@ class ReactWebView { return text } - public async postMessage(action: CR.Action): Promise { - // Send a message to the webview webview. - // You can send any JSON serializable data. - const success = await this.panel.webview.postMessage(action) - if (!success) { - throw new Error(`Message post failure: ${JSON.stringify(action)}`) - } - } - - public dispose(): void { - // Clean up our resources - this.panel.dispose() - - while (this.disposables.length) { - const x = this.disposables.pop() - if (x) { - x.dispose() - } - } - } - private getHtmlForWebview(): string { // eslint-disable-next-line const manifest = require(path.join(this.extensionPath, 'build', 'asset-manifest.json')) @@ -151,6 +151,8 @@ class ReactWebView { React App + + ({ + postMessage(event: string) { + console.log('postMessage', event) + } +}) + + // automatically import all files ending in *.stories.tsx const req = require.context('../stories', true, /\.stories\.tsx$/) diff --git a/web-app/src/Routes.tsx b/web-app/src/Routes.tsx index a2e8b03d..47dcf494 100644 --- a/web-app/src/Routes.tsx +++ b/web-app/src/Routes.tsx @@ -1,19 +1,27 @@ import * as React from 'react' -import Loading from './components/Loading' import Cond from './components/Cond' -import NewPage from './containers/New' +import Loading from './components/Loading' import ContinuePage from './containers/Continue' +import NewPage from './containers/New' import TutorialPage from './containers/Tutorial' interface Props { state: any } +const styles = { + page: { + width: window.innerWidth, + height: window.innerHeight, + backgroundColor: 'white', + }, +} + const Routes = ({ state }: Props) => { // TODO: refactor cond to user and accept first route as if/else if return ( -
+
diff --git a/web-app/src/index.tsx b/web-app/src/index.tsx index 5a20347a..fed66022 100644 --- a/web-app/src/index.tsx +++ b/web-app/src/index.tsx @@ -2,6 +2,7 @@ import React from 'react' import ReactDOM from 'react-dom' import App from './App' +// base styles import './styles/index.css' ReactDOM.render(, document.getElementById('root') as HTMLElement) diff --git a/web-app/src/utils/vscode.ts b/web-app/src/utils/vscode.ts index 7b6c14ad..97cc804d 100644 --- a/web-app/src/utils/vscode.ts +++ b/web-app/src/utils/vscode.ts @@ -2,12 +2,7 @@ import { Action } from 'typings' declare var acquireVsCodeApi: any -// @ts-ignore -const vscode = window.acquireVsCodeApi ? acquireVsCodeApi() : { - postMessage(event: string) { - console.log('postMessage', event) - } -} +const vscode = acquireVsCodeApi() export function send(event: string | Action) { return vscode.postMessage(event) diff --git a/web-app/stories/Stage.stories.tsx b/web-app/stories/Stage.stories.tsx index b75161b2..acf06089 100644 --- a/web-app/stories/Stage.stories.tsx +++ b/web-app/stories/Stage.stories.tsx @@ -38,7 +38,7 @@ function someExample(a) { `, }, hints: [], - status: { active: false, complete: true }, + status: { active: true, complete: false }, }, step3Id: { content: { @@ -46,7 +46,7 @@ function someExample(a) { text: 'Write a function `divide` that divides', }, hints: [], - status: { active: true, complete: false }, + status: { active: false, complete: false }, }, })} stage={object('stage', demo.data.stages.stage1Id)}