8000 Merge pull request #16 from ShMcK/feature/integrate · coderoad/coderoad-vscode@3d8c8fa · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3d8c8fa

Browse files
authored
Merge pull request #16 from ShMcK/feature/integrate
Feature/integrate
2 parents e2665b5 + 0002042 commit 3d8c8fa

File tree

8 files changed

+56
-41
lines changed

8 files changed

+56
-41
lines changed

src/editor/ReactWebView.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import * as vscode from 'vscode'
2-
import * as CR from 'typings'
31
import * as path from 'path'
2+
import * as CR from 'typings'
3+
import * as vscode from 'vscode'
44

55
/**
66
* Manages React webview panels
@@ -71,7 +71,7 @@ class ReactWebView {
7171
if (callback) {
7272
// listen for when webview is loaded
7373
// unfortunately there is no easy way of doing this
74-
let webPanelListener = setInterval(() => {
74+
const webPanelListener = setInterval(() => {
7575
if (this.loaded) {
7676
setTimeout(callback)
7777
clearInterval(webPanelListener)
@@ -80,6 +80,27 @@ class ReactWebView {
8080
}
8181
}
8282

83+
public async postMessage(action: CR.Action): Promise<void> {
84+
// Send a message to the webview webview.
85+
// You can send any JSON serializable data.
86+
const success = await this.panel.webview.postMessage(action)
87+
if (!success) {
88+
throw new Error(`Message post failure: ${JSON.stringify(action)}`)
89+
}
90+
}
91+
92+
public dispose(): void {
93+
// Clean up our resources
94+
this.panel.dispose()
95+
96+
while (this.disposables.length) {
97+
const x = this.disposables.pop()
98+
if (x) {
99+
x.dispose()
100+
}
101+
}
102+
}
103+
83104
private createWebviewPanel(column: number): vscode.WebviewPanel {
84105
const viewType = 'CodeRoad'
85106
const title = 'CodeRoad'
@@ -103,27 +124,6 @@ class ReactWebView {
103124
return text
104125
}
105126

106-
public async postMessage(action: CR.Action): Promise<void> {
107-
// Send a message to the webview webview.
108-
// You can send any JSON serializable data.
109-
const success = await this.panel.webview.postMessage(action)
110-
if (!success) {
111-
throw new Error(`Message post failure: ${JSON.stringify(action)}`)
112-
}
113-
}
114-
115-
public dispose(): void {
116-
// Clean up our resources
117-
this.panel.dispose()
118-
119-
while (this.disposables.length) {
120-
const x = this.disposables.pop()
121-
if (x) {
122-
x.dispose()
123-
}
124-
}
125-
}
126-
127127
private getHtmlForWebview(): string {
128128
// eslint-disable-next-line
129129
const manifest = require(path.join(this.extensionPath, 'build', 'asset-manifest.json'))
@@ -151,6 +151,8 @@ class ReactWebView {
151151
<meta name="theme-color" content="#000000">
152152
<title>React App</title>
153153
<link rel="manifest" href="./manifest.json" />
154+
<!-- TODO: load styles through package -->
155+
<link rel="stylesheet" href="https://unpkg.com/@alifd/next/dist/next.css" />
154156
<link rel="stylesheet" type="text/css" href="${styleUri}">
155157
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-resource: https:; script-src 'nonce-${n1}' 'nonce-${n2}' 'nonce-${n3}'; style-src vscode-resource: 'unsafe-inline' http: https: data:;">
156158
<base href="${vscode.Uri.file(path.join(this.extensionPath, 'build')).with({

src/editor/commands/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import * as vscode from 'vscode'
21
import { join } from 'path'
3-
import { setStorage } from '../storage'
2+
import * as CR from 'typings'
3+
import * as vscode from 'vscode'
44
import ReactWebView from '../ReactWebView'
5+
import { setStorage } from '../storage'
56
import { isEmptyWorkspace } from '../workspace'
6-
import * as CR from 'typings'
77
import runTest from './runTest'
88

99
const COMMANDS = {
@@ -44,7 +44,6 @@ export const createCommands = ({ context, machine, storage, git, position }: Cre
4444

4545
// activate machine
4646
webview = new ReactWebView(context.extensionPath)
47-
console.log('webview', webview.panel.webview.postMessage)
4847
machine.activate()
4948
},
5049
// open React webview

tslint.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"class-name": true,
99
"semicolon": [true, "never"],
1010
"triple-equals": true,
11-
"interface-name": [true, "never-prefix"]
11+
"interface-name": [true, "never-prefix"],
12+
"object-literal-sort-keys": false
1213
},
1314
"defaultSeverity": "warning",
1415
"no-submodule-imports": false

web-app/.storybook/config.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
import '@alifd/next/dist/next.css'
1+
// import '@alifd/next/dist/next.css'
22
import { configure } from '@storybook/react'
33
import '../src/styles/index.css'
44

5+
// setup acquireVsCodeApi mock
6+
// @ts-ignore
7+
global.acquireVsCodeApi = () => ({
8+
postMessage(event: string) {
9+
console.log('postMessage', event)
10+
}
11+
})
12+
13+
514
// automatically import all files ending in *.stories.tsx
615
const req = require.context('../stories', true, /\.stories\.tsx$/)
716

web-app/src/Routes.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
import * as React from 'react'
22

3-
import Loading from './components/Loading'
43
import Cond from './components/Cond'
5-
import NewPage from './containers/New'
4+
import Loading from './components/Loading'
65
import ContinuePage from './containers/Continue'
6+
import NewPage from './containers/New'
77
import TutorialPage from './containers/Tutorial'
88

99
interface Props {
1010
state: any
1111
}
1212

13+
const styles = {
14+
page: {
15+
width: window.innerWidth,
16+
height: window.innerHeight,
17+
backgroundColor: 'white',
18+
},
19+
}
20+
1321
const Routes = ({ state }: Props) => {
1422
// TODO: refactor cond to user <Router><Route> and accept first route as if/else if
1523
return (
16-
<div>
24+
<div style={styles.page}>
1725
<Cond state={state} path="SelectTutorial.Startup">
1826
<Loading />
1927
</Cond>

web-app/src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react'
22
import ReactDOM from 'react-dom'
33
import App from './App'
44

5+
// base styles
56
import './styles/index.css'
67

78
ReactDOM.render(<App />, document.getElementById('root') as HTMLElement)

web-app/src/utils/vscode.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ import { Action } from 'typings'
22

33
declare var acquireVsCodeApi: any
44

5-
// @ts-ignore
6-
const vscode = window.acquireVsCodeApi ? acquireVsCodeApi() : {
7-
postMessage(event: string) {
8-
console.log('postMessage', event)
9-
}
10-
}
5+
const vscode = acquireVsCodeApi()
116

127
export function send(event: string | Action) {
138
return vscode.postMessage(event)

web-app/stories/Stage.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ function someExample(a) {
3838
`,
3939
},
4040
hints: [],
41-
status: { active: false, complete: true },
41+
status: { active: true, complete: false },
4242
},
4343
step3Id: {
4444
content: {
4545
title: 'Divide',
4646
text: 'Write a function `divide` that divides',
4747
},
4848
hints: [],
49-
status: { active: true, complete: false },
49+
status: { active: false, complete: false },
5050
},
5151
})}
5252
stage={object('stage', demo.data.stages.stage1Id)}

0 commit comments

Comments
 (0)
0