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

Commitf462b39

Browse files
committed
heavy refactor
1 parent0ad9d2c commitf462b39

File tree

8 files changed

+65
-71
lines changed

8 files changed

+65
-71
lines changed

‎src/editor/commands/index.ts

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import * as G from 'typings/graphql'
44
import*asvscodefrom'vscode'
55
importReactWebViewfrom'../ReactWebView'
66
importstoragefrom'../storage'
7-
import{isEmptyWorkspace}from'../workspace'
87
importrunTestfrom'./runTest'
8+
import{isEmptyWorkspace}from'../workspace'
99

1010
constCOMMANDS={
1111
START:'coderoad.start',
12-
TUTORIAL_LAUNCH:'coderoad.tutorial_launch',
13-
TUTORIAL_SETUP:'coderoad.tutorial_setup',
12+
TEST_RUNNER_SETUP:'coderoad.test_runner_setup',
1413
OPEN_WEBVIEW:'coderoad.open_webview',
1514
SEND_STATE:'coderoad.send_state',
1615
SEND_DATA:'coderoad.send_data',
@@ -24,7 +23,6 @@ const COMMANDS = {
2423
interfaceCreateCommandProps{
2524
vscodeExt:vscode.ExtensionContext
2625
machine:CR.StateMachine
27-
git:any
2826
}
2927

3028
constresetLayout=()=>{
@@ -34,13 +32,15 @@ const resetLayout = () => {
3432
})
3533
}
3634

37-
exportconstcreateCommands=({vscodeExt, machine, git}:CreateCommandProps)=>{
35+
exportconstcreateCommands=({vscodeExt, machine}:CreateCommandProps)=>{
3836
// React panel webview
3937
letwebview:any
4038

4139
return{
4240
// initialize
43-
[COMMANDS.START]:()=>{
41+
[COMMANDS.START]:async()=>{
42+
43+
awaitisEmptyWorkspace()
4444

4545
letwebviewState:'INITIALIZING'|'RESTARTING'
4646
if(!webview){
@@ -77,24 +77,7 @@ export const createCommands = ({vscodeExt, machine, git}: CreateCommandProps) =>
7777
}
7878
webview.createOrShow(column,callback)
7979
},
80-
// launch a new tutorial
81-
// NOTE: may be better to move into action as logic is primarily non-vscode
82-
[COMMANDS.TUTORIAL_LAUNCH]:async(repo:G.TutorialRepo)=>{
83-
console.log('launch tutorial')
84-
85-
awaitisEmptyWorkspace()
86-
87-
awaitgit.gitInitIfNotExists()
88-
89-
if(!repo||!repo.uri){
90-
thrownewError('Tutorial repo uri not found')
91-
}
92-
93-
awaitgit.gitSetupRemote(repo.uri)
94-
95-
machine.send('TUTORIAL_LOADED')
96-
},
97-
[COMMANDS.TUTORIAL_SETUP]:async(codingLanguage:G.EnumCodingLanguage)=>{
80+
[COMMANDS.TEST_RUNNER_SETUP]:async(codingLanguage:G.EnumCodingLanguage)=>{
9881

9982
// TODO: allow multiple coding languages in a tutorial
10083

‎src/editor/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import*asvscodefrom'vscode'
22
import*asCRfrom'typings'
33
import{createCommands}from'./commands'
4-
import*asgitfrom'../services/git'
54

65
interfaceProps{
76
machine:CR.StateMachine
@@ -53,7 +52,6 @@ class Editor {
5352
constcommands=createCommands({
5453
vscodeExt:this.vscodeExt,
5554
machine:this.machine,
56-
git,
5755
})
5856
for(constcmdincommands){
5957
constcommand:vscode.Disposable=vscode.commands.registerCommand(cmd,commands[cmd])

‎src/editor/storage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import*asvscodefrom'vscode'
22

3-
classStorage{
3+
classEditorStorage{
44
privatestorage:vscode.Memento
55
constructor(){
66
this.storage={}asvscode.Memento
@@ -19,4 +19,4 @@ class Storage {
1919
}
2020
}
2121

22-
exportdefaultnewStorage()
22+
exportdefaultnewEditorStorage()

‎src/services/tutorial/index.ts

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ interface TutorialConfig {
99
testRunner:G.EnumTestRunner
1010
}
1111

12-
interfacePositionProgress{
12+
interfaceMessageData{
13+
tutorial?:{id:string}
1314
position:CR.Position
1415
progress:CR.Progress
1516
}
@@ -20,12 +21,11 @@ export interface TutorialModel {
2021
version:G.TutorialVersion
2122
position:CR.Position
2223
progress:CR.Progress
23-
init(tutorial:G.Tutorial):void
24-
load(tutorialId:string):void
24+
launch(tutorialId:string):void
2525
level(levelId?:string):G.Level
2626
stage(stageId?:string):G.Stage
2727
step(stepId?:string):G.Step
28-
updateProgress():PositionProgress
28+
updateProgress():void
2929
nextPosition():CR.Position
3030
hasExisting():Promise<boolean>
3131
setClientDispatch(editorDispatch:CR.EditorDispatch):void
@@ -37,11 +37,11 @@ class Tutorial implements TutorialModel {
3737
publicversion:G.TutorialVersion
3838
publicposition:CR.Position
3939
publicprogress:CR.Progress
40-
privateclientDispatch:(props:PositionProgress)=>void
40+
privateclientDispatch:(props:MessageData)=>void
4141

4242
constructor(){
4343
// initialize types, will be assigned when tutorial is selected
44-
this.clientDispatch=(props:PositionProgress)=>{
44+
this.clientDispatch=(props:MessageData)=>{
4545
thrownewError('Tutorial client dispatch yet initialized')
4646
}
4747
this.repo={}asG.TutorialRepo
@@ -62,10 +62,18 @@ class Tutorial implements TutorialModel {
6262
}
6363

6464
publicsetClientDispatch(editorDispatch:CR.EditorDispatch){
65-
this.clientDispatch=({progress, position}:PositionProgress)=>editorDispatch('coderoad.send_data',{progress, position})
65+
this.clientDispatch=({progress, position}:MessageData)=>editorDispatch('coderoad.send_data',{progress, position})
6666
}
6767

68-
publicinit=(tutorial:G.Tutorial)=>{
68+
publicasynclaunch(tutorialId:string){
69+
const{tutorial}:{tutorial:G.Tutorial|null}=awaitapi.request(tutorialQuery,{
70+
tutorialId,// TODO: add selection of tutorial id
71+
})
72+
73+
if(!tutorial){
74+
thrownewError(`Tutorial${tutorialId} not found`)
75+
}
76+
6977
this.repo=tutorial.repo
7078
this.config={
7179
codingLanguage:tutorial.codingLanguage,
@@ -90,6 +98,7 @@ class Tutorial implements TutorialModel {
9098
console.log('this.position',JSON.stringify(this.position))
9199

92100
this.clientDispatch({
101+
tutorial:{id:tutorial.id},
93102
position:this.position,
94103
progress:this.progress
95104
})
@@ -111,19 +120,6 @@ class Tutorial implements TutorialModel {
111120

112121
return!!(tutorial&&progress)
113122
}
114-
115-
publicasyncload(tutorialId:string){
116-
// TODO: load from localStorage
117-
const{tutorial}:{tutorial:G.Tutorial|null}=awaitapi.request(tutorialQuery,{
118-
tutorialId,// TODO: add selection of tutorial id
119-
})
120-
121-
if(!tutorial){
122-
thrownewError(`Tutorial${tutorialId} not found`)
123-
}
124-
125-
awaitthis.init(tutorial)
126-
}
127123
publiclevel=(levelId:string):G.Level=>{
128124
constlevel:G.Level|undefined=this.version.levels.find((l:G.Level)=>l.id===levelId||this.position.levelId)
129125
if(!level){
@@ -147,15 +143,16 @@ class Tutorial implements TutorialModel {
147143
}
148144
returnstep
149145
}
150-
publicupdateProgress=():{position:CR.Position,progress:CR.Progress}=>{
146+
publicupdateProgress=()=>{
151147
const{levelId, stageId, stepId}=this.position
152148
this.progress.levels[levelId]=true
153149
this.progress.stages[stageId]=true
154150
this.progress.steps[stepId]=true
155-
return{
156-
position:this.position,
151+
152+
this.clientDispatch({
157153
progress:this.progress,
158-
}
154+
position:this.position,// TODO: calculate next position
155+
})
159156
}
160157
publicnextPosition=():CR.Position=>{
161158
const{levelId, stageId, stepId}=this.position

‎src/state/actions/index.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import{assign}from'xstate'
21
// NOTE: codesmell - importing machine
32
import{machine}from'../../extension'
43
import{TutorialModel}from'../../services/tutorial'
@@ -30,18 +29,33 @@ export default (editorDispatch: CR.EditorDispatch, tutorialModel: TutorialModel)
3029
asynctutorialLaunch(){
3130
consttutorialId:string='1'
3231
// TODO: load tutorialId
33-
awaittutorialModel.load(tutorialId)
32+
awaittutorialModel.launch(tutorialId)
33+
34+
// git setup
3435
constrepo:G.TutorialRepo=tutorialModel.repo
3536

36-
editorDispatch('coderoad.tutorial_launch',repo)
37+
console.log('launch tutorial')
38+
39+
awaitgit.gitInitIfNotExists()
40+
41+
if(!repo||!repo.uri){
42+
thrownewError('Tutorial repo uri not found')
43+
}
44+
45+
awaitgit.gitSetupRemote(repo.uri)
46+
47+
machine.send('TUTORIAL_LOADED')
3748
},
38-
tutorialSetup(){
49+
testRunnerSetup(){
3950
constcodingLanguage:G.EnumCodingLanguage=tutorialModel.config.codingLanguage
40-
editorDispatch('coderoad.tutorial_setup',codingLanguage)
51+
editorDispatch('coderoad.test_runner_setup',codingLanguage)
4152
},
4253
initializeNewTutorial:()=>{
4354
console.log('initializeNewTutorial')
4455
},
56+
tutorialContinue(){
57+
console.log('tutorial continue')
58+
},
4559
// tutorialContinue: assign({
4660
// // load initial data, progress & position
4761
// data(): CR.TutorialData {

‎src/state/machine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const machine = (editorDispatch: CR.EditorDispatch, tutorialModel: Tutori
5454
Tutorial:{
5555
id:'tutorial',
5656
initial:'Initialize',
57-
onEntry:['tutorialSetup'],
57+
onEntry:['testRunnerSetup'],
5858
on:{
5959
WEBVIEW_INITIALIZED:'#tutorial-load-next'
6060
},

‎web-app/src/App.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ const App = () => {
1717

1818
// set state machine state
1919
const[state,setState]=React.useState(initialState)
20-
const[debuggerInfo,setDebuggerInfo]=React.useState({})
20+
const[debuggerInfo,setDebuggerInfo]=React.useState({
21+
progress:{levels:{},stages:{},steps:{},complete:false},
22+
position:{levelId:'',stageId:'',stepId:''},
23+
})
2124

2225
// update level/stage/step status based on user progress & position
2326
// TODO: model server more effeciently
@@ -38,6 +41,7 @@ const App = () => {
3841
// SET_DATA - set state machine context
3942
const{ progress, position}=message.payload.data
4043
if(process.env.REACT_APP_DEBUG){
44+
console.log(`Position:${position.levelId}/${position.stageId}/${position.stepId}`)
4145
setDebuggerInfo({ progress, position})
4246
}
4347
setStatus({variables:{ progress, position}})
@@ -56,15 +60,11 @@ const App = () => {
5660
send('WEBVIEW_LOADED')
5761
},[])
5862

59-
constvalue={
60-
state,
61-
}
62-
6363
// TODO: refactor cond to user <Router><Route> and accept first route as if/else if
6464
return(
6565
<ApolloProviderclient={client}>
6666
<div>
67-
{process.env.REACT_APP_DEBUG&&<Debuggervalue={{...value,debuggerInfo}}/>}
67+
{process.env.REACT_APP_DEBUG&&<Debuggerstate={state}{...debuggerInfo}/>}
6868
<Routesstate={state}/>
6969
</div>
7070
</ApolloProvider>

‎web-app/src/components/Debugger/index.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import*asReactfrom'react'
2+
import*asCRfrom'typings'
23

34
interfaceProps{
4-
value:any
5+
state:object
6+
position:CR.Position
7+
progress:CR.Progress
58
}
69

7-
constDebugger=({value}:Props)=>(
10+
constDebugger=({state, position, progress}:Props)=>(
811
<divstyle={{backgroundColor:'#FFFF99',color:'black',padding:'.5rem'}}>
9-
<h4>state:{JSON.stringify(value.state)}</h4>
10-
<pstyle={{backgroundColor:'khaki',padding:'.5rem'}}>position:{JSON.stringify(value.position)}</p>
11-
<pstyle={{backgroundColor:'moccasin',padding:'.5rem'}}>progress:{JSON.stringify(value.progress)}</p>
12-
<pstyle={{backgroundColor:'papayawhip',padding:'.5rem'}}>data:{JSON.stringify(value.data)}</p>
12+
<h4>state:{JSON.stringify(state)}</h4>
13+
<pstyle={{backgroundColor:'khaki',padding:'.5rem'}}>position:{JSON.stringify(position)}</p>
14+
<pstyle={{backgroundColor:'moccasin',padding:'.5rem'}}>progress:{JSON.stringify(progress)}</p>
1315
</div>
1416
)
1517

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp