Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ShMcK merged 12 commits intomasterfromfeature/tutorial-setup
Jun 9, 2019
Merged
Show file tree
Hide file tree
Changes from1 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
PrevPrevious commit
NextNext commit
run received actions through state machine
  • Loading branch information
@ShMcK
ShMcK committedJun 9, 2019
commit08b28afd3d66695d663a5dcc0afbef93735f1ef6
6 changes: 3 additions & 3 deletionssrc/editor/ReactWebView.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand All@@ -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')
}

Expand Down
16 changes: 5 additions & 11 deletionssrc/editor/commands/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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',
}
Expand All@@ -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
Expand All@@ -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()
},
Expand All@@ -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'
Expand DownExpand Up@@ -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 deletionssrc/state/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletiontypings/index.d.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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 deletionweb-app/src/Routes.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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 => {
Expand All@@ -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={[]} />
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp