|
1 | | -import{send}from'xstate' |
2 | | -// import {machine} from '../../extension' |
3 | | -// import {cache} from '../../services/apollo' |
4 | | -// import {editorDispatch} from '../../services/vscode' |
5 | | -import*asCRfrom'typings' |
6 | | -import*asGfrom'typings/graphql' |
7 | | -// import tutorialConfig from '../../services/apollo/queries/tutorialConfig' |
8 | 1 | importeditorActionsfrom'./editor' |
9 | 2 | importcontextActionsfrom'./context' |
| 3 | +importapiActionsfrom'./api' |
10 | 4 |
|
11 | 5 | exportdefault{ |
12 | | -newOrContinue:send((context:CR.MachineContext):'NEW'|'CONTINUE'=>{ |
13 | | -console.log('new or continue') |
14 | | - |
15 | | -// TODO: verify that the user has an existing tutorial to continue |
16 | | -consthasExistingTutorial:boolean=false |
17 | | -returnhasExistingTutorial ?'CONTINUE' :'NEW' |
18 | | -}), |
19 | | -stepNext:send((context:CR.MachineContext):CR.Action=>{ |
20 | | -const{tutorial, position, progress}=context |
21 | | -// TODO: protect against errors |
22 | | -conststeps:G.Step[]=tutorial.version |
23 | | -.levels.find((l:G.Level)=>l.id===position.levelId) |
24 | | -.stages.find((s:G.Stage)=>s.id===position.stageId) |
25 | | -.steps |
26 | | - |
27 | | -// TODO: verify not -1 |
28 | | -conststepIndex=steps.findIndex((s:G.Step)=>s.id===position.stepId) |
29 | | -constfinalStep=stepIndex===steps.length-1 |
30 | | -conststepComplete=progress.steps[position.stepId] |
31 | | -// not final step, or final step but not complete |
32 | | -consthasNextStep=!finalStep||!stepComplete |
33 | | - |
34 | | -if(hasNextStep){ |
35 | | -constnextStep=steps[stepIndex+1] |
36 | | -return{ |
37 | | -type:'LOAD_NEXT_STEP', |
38 | | -payload:{ |
39 | | -step:nextStep |
40 | | -} |
41 | | -} |
42 | | -}else{ |
43 | | -return{ |
44 | | -type:'STAGE_COMPLETE' |
45 | | -} |
46 | | -} |
47 | | - |
48 | | -}), |
49 | 6 | ...editorActions, |
50 | 7 | ...contextActions, |
| 8 | +...apiActions, |
51 | 9 | } |
52 | | - |
53 | | -// export default { |
54 | | -// async newOrContinue() { |
55 | | -// // verify that the user has an existing tutorial to continue |
56 | | -// // const hasExistingTutorial: boolean = await tutorialModel.hasExisting() |
57 | | -// // machine.send(hasExistingTutorial ? 'CONTINUE' : 'NEW') |
58 | | -// }, |
59 | | -// testRunnerSetup() { |
60 | | -// const result = cache.readQuery({query: tutorialConfig}) |
61 | | -// console.log('result', result) |
62 | | -// // const codingLanguage: G.EnumCodingLanguage = result.data.codingLanguage |
63 | | -// // editorDispatch('coderoad.test_runner_setup', codingLanguage) |
64 | | -// }, |
65 | | -// initializeNewTutorial: assign({ |
66 | | -// position: (context: any): CR.Position => { |
67 | | -// const { tutorial } = context |
68 | | -// const levelId = data.summary.levelList[0] |
69 | | -// const stageId = data.levels[levelId].stageList[0] |
70 | | -// const stepId = data.stages[stageId].stepList[0] |
71 | | -// return { |
72 | | -// levelId, |
73 | | -// stageId, |
74 | | -// stepId, |
75 | | -// } |
76 | | -// }, |
77 | | -// }) |
78 | | -// tutorialContinue() { |
79 | | -// console.log('tutorial continue') |
80 | | -// }, |
81 | | -// testStart() { |
82 | | -// editorDispatch('coderoad.run_test') |
83 | | -// }, |
84 | | -// testPass(): void { |
85 | | -// editorDispatch('coderoad.test_pass') |
86 | | -// // git.gitSaveCommit(tutorialModel.position) |
87 | | -// }, |
88 | | -// testFail() { |
89 | | -// editorDispatch('coderoad.test_fail') |
90 | | -// }, |
91 | | -// //@ts-ignore |
92 | | -// progressUpdate() { |
93 | | -// // tutorialModel.updateProgress() |
94 | | -// // tutorialModel.nextPosition() |
95 | | -// }, |
96 | | - |
97 | | -// stageLoadNext() { |
98 | | -// console.log('stageLoadNext') |
99 | | -// // tutorialModel.nextPosition() |
100 | | -// }, |
101 | | -// loadStage(): void { |
102 | | -// // tutorialModel.triggerCurrent('STAGE') |
103 | | -// }, |
104 | | -// stepLoadCommits(): void { |
105 | | -// // tutorialModel.triggerCurrent('STEP') |
106 | | -// }, |
107 | | -// } |