Skip to content

Feature/tutorial setup #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 9, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
run received actions through state machine
  • Loading branch information
ShMcK committed Jun 9, 2019
commit 08b28afd3d66695d663a5dcc0afbef93735f1ef6
6 changes: 3 additions & 3 deletions src/editor/ReactWebView.ts
Original file line number Diff line number Diff line change
@@ -12,9 +12,8 @@ class ReactWebView {
private disposables: vscode.Disposable[] = []
private onReceive: any // TODO: properly type

public constructor(extensionPath: string, onReceive: any) {
public constructor(extensionPath: string) {
this.extensionPath = extensionPath
this.onReceive = onReceive

// Create and show a new webview panel
this.panel = this.createWebviewPanel(vscode.ViewColumn.One)
@@ -27,7 +26,8 @@ class ReactWebView {
this.panel.onDidDispose(() => this.dispose(), null, this.disposables)

// Handle messages from the webview
this.panel.webview.onDidReceiveMessage(this.onReceive, null, this.disposables)
const onReceive = (action: string | CR.Action) => vscode.commands.executeCommand('coderoad.receive_action', action)
this.panel.webview.onDidReceiveMessage(onReceive, null, this.disposables)
console.log('webview loaded')
}

16 changes: 5 additions & 11 deletions src/editor/commands/index.ts
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ const COMMANDS = {
NEW_OR_CONTINUE: 'coderoad.new_or_continue',
OPEN_WEBVIEW: 'coderoad.open_webview',
SEND_STATE: 'coderoad.send_state',
RECEIVE_ACTION: 'coderoad.receive_action',
OPEN_FILE: 'coderoad.open_file',
RUN_TEST: 'coderoad.test_run',
}
@@ -22,13 +23,6 @@ interface CreateCommandProps {

// React panel webview
let webview: any;
let initialTutorial: CR.Tutorial | undefined
let initialProgress: CR.Progress = {
levels: {},
stages: {},
steps: {},
complete: false,
}

export const createCommands = ({ context, machine, storage, git }: CreateCommandProps) => ({
// initialize
@@ -37,7 +31,7 @@ export const createCommands = ({ context, machine, storage, git }: CreateCommand
setStorage(context.workspaceState)

// activate machine
webview = new ReactWebView(context.extensionPath, machine.onReceive)
webview = new ReactWebView(context.extensionPath)
console.log('webview', webview.panel.webview.postMessage)
machine.activate()
},
@@ -50,8 +44,6 @@ export const createCommands = ({ context, machine, storage, git }: CreateCommand
git.gitVersion(),
git.gitCheckRemoteExists(),
])
initialTutorial = tutorial
initialProgress = progress
const canContinue = !!(tutorial && progress && hasGit && hasGitRemote)
console.log('canContinue', canContinue)
// if a tutorial exists, 'CONTINUE'
@@ -85,6 +77,8 @@ export const createCommands = ({ context, machine, storage, git }: CreateCommand
// throw new Error('No valid panel available')
// }
webview.postMessage({ type: 'SET_STATE', payload })

},
[COMMANDS.RECEIVE_ACTION]: (action: string | CR.Action) => {
machine.onReceive(action)
}
})
4 changes: 2 additions & 2 deletions src/state/index.ts
Original file line number Diff line number Diff line change
@@ -38,9 +38,9 @@ class StateMachine {
console.log(action)
this.service.send(action)
}
onReceive(action: CR.Action) {
console.log('RECEIVED ACTION')
onReceive(action: string | CR.Action) {
console.log(action)
this.service.send(action)
}
}

2 changes: 1 addition & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
@@ -168,5 +168,5 @@ export interface StateMachine {
activate(): void
deactivate(): void
send(action: string | Action): void
onReceive(action: Action): void
onReceive(action: string | Action): void
}
11 changes: 10 additions & 1 deletion web-app/src/Routes.tsx
Original file line number Diff line number Diff line change
@@ -8,6 +8,15 @@ interface ReceivedEvent {
data: CR.Action
}

declare var acquireVsCodeApi: any

const vscode = acquireVsCodeApi()

function send(event: string|CR.Action) {
return vscode.postMessage(event)
}


const Routes = () => {
const [state, setState] = React.useState({ SelectTutorial: 'Initial' })
const handleEvent = (event: ReceivedEvent): void => {
@@ -31,7 +40,7 @@ const Routes = () => {
return (
<div>
<Cond state={state} path="SelectTutorial.NewTutorial">
<NewPage onNew={() => console.log('new!')} />
<NewPage onNew={() => send('TUTORIAL_START')} />
</Cond>
<Cond state={state} path="SelectTutorial.ContinueTutorial">
<ContinuePage onContinue={() => console.log('continue!')} tutorials={[]} />