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

Commit90c054b

Browse files
authored
Merge pull requestcoderoad#5 from ShMcK/feature/new-continue
Feature/new continue
2 parentsbf04c34 +7c2bd8f commit90c054b

File tree

27 files changed

+243
-275
lines changed

27 files changed

+243
-275
lines changed

‎package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"compile":"tsc -p ./",
3333
"watch":"tsc -watch -p ./",
3434
"postinstall":"node ./node_modules/vscode/bin/install",
35+
"storybook":"cd web-app && npm run storybook",
3536
"test":"npm run build && node ./node_modules/vscode/bin/test"
3637
},
3738
"devDependencies": {

‎src/editor/commands/index.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import * as vscode from 'vscode'
22
import{join}from'path'
33
import{setStorage}from'../storage'
44
importReactWebViewfrom'../ReactWebView'
5+
import{isEmptyWorkspace}from'../workspace'
56
import*asCRfrom'typings'
67

78
constCOMMANDS={
89
START:'coderoad.start',
9-
NEW_OR_CONTINUE:'coderoad.new_or_continue',
10+
TUTORIAL_LAUNCH:'coderoad.tutorial_launch',
1011
OPEN_WEBVIEW:'coderoad.open_webview',
1112
SEND_STATE:'coderoad.send_state',
1213
SEND_DATA:'coderoad.send_data',
@@ -20,12 +21,13 @@ interface CreateCommandProps {
2021
machine:CR.StateMachine,
2122
storage:any,
2223
git:any
24+
position:any
2325
}
2426

2527
// React panel webview
2628
letwebview:any;
2729

28-
exportconstcreateCommands=({ context, machine, storage, git}:CreateCommandProps)=>({
30+
exportconstcreateCommands=({ context, machine, storage, git, position}:CreateCommandProps)=>({
2931
// initialize
3032
[COMMANDS.START]:()=>{
3133
// set local storage workspace
@@ -36,25 +38,30 @@ export const createCommands = ({ context, machine, storage, git }: CreateCommand
3638
console.log('webview',webview.panel.webview.postMessage)
3739
machine.activate()
3840
},
39-
[COMMANDS.NEW_OR_CONTINUE]:async()=>{
40-
// verify that the user has a tutorial & progress
41-
// verify git is setup with a coderoad remote
42-
const[tutorial,progress,hasGit,hasGitRemote]=awaitPromise.all([
43-
storage.getTutorial(),
44-
storage.getProgress(),
45-
git.gitVersion(),
46-
git.gitCheckRemoteExists(),
47-
])
48-
constcanContinue=!!(tutorial&&progress&&hasGit&&hasGitRemote)
49-
console.log('canContinue',canContinue)
50-
// if a tutorial exists, 'CONTINUE'
51-
// otherwise start from 'NEW'
52-
machine.send(canContinue ?'CONTINUE' :'NEW')
53-
},
5441
// open React webview
5542
[COMMANDS.OPEN_WEBVIEW]:(column:number=vscode.ViewColumn.One)=>{
5643
webview.createOrShow(column);
5744
},
45+
// launch a new tutorial
46+
// NOTE: may be better to move into action as logic is primarily non-vscode
47+
[COMMANDS.TUTORIAL_LAUNCH]:async(tutorial:CR.Tutorial)=>{
48+
console.log('launch tutorial')
49+
50+
awaitisEmptyWorkspace()
51+
52+
awaitgit.gitInitIfNotExists()
53+
54+
// TODO: use actual tutorial repo
55+
awaitPromise.all([git.gitSetupRemote(tutorial.meta.repo),storage.setTutorial(tutorial),storage.resetProgress()])
56+
57+
// TODO: refactor to allow client to call initialization
58+
constpos:CR.Position=awaitposition.getInitial(tutorial)
59+
60+
// eslint-disable-next-line
61+
const{ steps}=tutorial.data
62+
const{ setup}=steps[pos.stepId].actions
63+
awaitgit.gitLoadCommits(setup)
64+
},
5865
// open a file
5966
[COMMANDS.OPEN_FILE]:async(relativeFilePath:string)=>{
6067
console.log(`OPEN_FILE${JSON.stringify(relativeFilePath)}`)
@@ -79,6 +86,6 @@ export const createCommands = ({ context, machine, storage, git }: CreateCommand
7986
},
8087
[COMMANDS.RECEIVE_ACTION]:(action:string|CR.Action)=>{
8188
console.log('onReceiveAction',action)
82-
machine.onReceive(action)
89+
machine.send(action)
8390
}
8491
})

‎src/editor/commands/start-old.ts

Lines changed: 0 additions & 108 deletions
This file was deleted.

‎src/editor/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as CR from 'typings'
33
import{createCommands}from'./commands'
44
import*asstoragefrom'../services/storage'
55
import*asgitfrom'../services/git'
6+
import*aspositionfrom'../services/position'
67

78
interfaceProps{
89
machine:CR.StateMachine,
@@ -33,6 +34,7 @@ class Editor {
3334
machine:this.machine,
3435
storage,
3536
git,
37+
position,
3638
})
3739
for(constcmdincommands){
3840
constcommand:vscode.Disposable=vscode.commands.registerCommand(cmd,commands[cmd])

‎src/services/api/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import*asCRfrom'typings'
22

33
// temporary tutorials
4-
importbasicTutorialfrom'../../state/context/tutorials/basic'
4+
importbasicTutorialfrom'tutorials/basic'
55

66
interfaceOptions{
77
resource:string

‎src/state/actions/index.ts

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import{assign}from'xstate'
2+
// NOTE: codesmell - importing machine
3+
import{machine}from'../../extension'
4+
importapifrom'../../services/api'
25
import*asCRfrom'typings'
36
import*asvscodefrom'vscode'
7+
import*asstoragefrom'../../services/storage'
8+
import*asgitfrom'../../services/git'
49

510
letinitialTutorial:CR.Tutorial|undefined
611
letinitialProgress:CR.Progress={
@@ -11,7 +16,34 @@ let initialProgress: CR.Progress = {
1116
}
1217

1318
exportdefault{
14-
tutorialLoad:assign({
19+
createWebview(){
20+
console.log('execute coderoad.open_webview')
21+
vscode.commands.executeCommand('coderoad.open_webview')
22+
},
23+
asyncnewOrContinue(){
24+
// verify that the user has a tutorial & progress
25+
// verify git is setup with a coderoad remote
26+
const[tutorial,progress,hasGit,hasGitRemote]=awaitPromise.all([
27+
storage.getTutorial(),
28+
storage.getProgress(),
29+
git.gitVersion(),
30+
git.gitCheckRemoteExists(),
31+
])
32+
constcanContinue=!!(tutorial&&progress&&hasGit&&hasGitRemote)
33+
34+
if(canContinue){
35+
initialTutorial=tutorial
36+
initialProgress=progress
37+
}
38+
39+
machine.send(canContinue ?'CONTINUE' :'NEW')
40+
},
41+
asynctutorialLaunch(){
42+
// TODO: add selection of tutorial id
43+
consttutorial:CR.Tutorial=awaitapi({resource:'getTutorial',params:{id:'1'}})
44+
vscode.commands.executeCommand('coderoad.tutorial_launch',tutorial)
45+
},
46+
tutorialContinue:assign({
1547
// load initial data, progress & position
1648
data():CR.TutorialData{
1749
console.log('ACTION: tutorialLoad.data')
@@ -45,11 +77,4 @@ export default {
4577
returnposition
4678
}
4779
}),
48-
createWebview(){
49-
console.log('execute coderoad.open_webview')
50-
vscode.commands.executeCommand('coderoad.open_webview')
51-
},
52-
newOrContinue(){
53-
vscode.commands.executeCommand('coderoad.new_or_continue')
54-
}
5580
}

‎src/state/context/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
importbasicTutorialDatafrom'./tutorials/basic'
1+
importbasicTutorialDatafrom'tutorials/basic'
22
import*asCRfrom'typings'
33

44
consttutorialContext:CR.MachineContext={

‎src/state/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ class StateMachine {
3636
this.service.stop()
3737
}
3838
send(action:string|CR.Action){
39-
console.log('machine.send')
40-
console.log(action)
41-
this.service.send(action)
42-
}
43-
onReceive(action:string|CR.Action){
44-
console.log(action)
4539
this.service.send(action)
4640
}
4741
}

‎src/state/machine.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const machine = Machine<
1111
CR.MachineEvent
1212
>(
1313
{
14-
id:'tutorial',
14+
id:'root',
1515
context:initialContext,
1616
initial:'SelectTutorial',
1717
states:{
@@ -40,28 +40,28 @@ export const machine = Machine<
4040
},
4141
},
4242
InitializeTutorial:{
43+
onEntry:['tutorialLaunch'],
4344
on:{
44-
TUTORIAL_LOADED:'Tutorial'
45+
TUTORIAL_LOADED:'#tutorial'
4546
}
4647
},
4748
}
48-
4949
},
5050
ContinueTutorial:{
51-
onEntry:'tutorialLoad',
51+
onEntry:['tutorialContinue'],
5252
on:{
53-
TUTORIAL_START:{
54-
target:'Tutorial.LoadNext',
55-
}
53+
TUTORIAL_START:'#tutorial-load-next'
5654
}
5755
},
5856
}
5957
},
6058
Tutorial:{
59+
id:'tutorial',
6160
initial:'Summary',
6261
states:{
6362
LoadNext:{
64-
onEntry:()=>send('LOAD_NEXT'),
63+
id:'tutorial-load-next',
64+
// onEntry: [() => send('LOAD_NEXT')],
6565
on:{
6666
LOAD_NEXT:[
6767
{
@@ -144,7 +144,7 @@ export const machine = Machine<
144144
cond:'hasNextLevel',
145145
},
146146
{
147-
target:'EndTutorial',
147+
target:'#root.Tutorial.EndTutorial',
148148
},
149149
],
150150
},

‎src/state/message.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"dom"
99
],
1010
"sourceMap":true,
11-
"rootDir":"src",
11+
"rootDirs":["src","tutorials"],
1212
"baseUrl":"src",
1313
"strict":true,/* enable all strict type-checking options*/
1414
/* Additional Checks*/
@@ -23,6 +23,9 @@
2323
"emitDecoratorMetadata":true,
2424
"paths": {
2525
"typings": ["../typings/index.d.ts"],
26+
"tutorials/basic": [
27+
"../tutorials/basic.ts"
28+
]
2629
},
2730
},
2831
"exclude": [

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp