|
1 | | -// import * as CR from 'typings' |
2 | | -// import {TutorialModel} from '../../services/tutorial' |
3 | | - |
4 | | - |
5 | | -exportdefault{} |
| 1 | +import*asGfrom'typings/graphql' |
| 2 | +import*asCRfrom'typings' |
6 | 3 |
|
7 | 4 | // // TODO: refactor into a single calculation |
8 | | -// export default (tutorialModel: TutorialModel) => ({ |
9 | | -// hasNextStep: (): boolean => { |
10 | | - |
11 | | -// const nextPosition: CR.Position = tutorialModel.nextPosition() |
12 | | - |
13 | | -// const sameStage = nextPosition.stageId === tutorialModel.position.stageId |
14 | | -// const sameStep = nextPosition.stepId === tutorialModel.position.stepId |
15 | | - |
16 | | -// const hasNext: boolean = sameStage && sameStep |
17 | | - |
18 | | -// console.log('GUARD: hasNextStep', hasNext) |
19 | | -// return hasNext |
20 | | -// }, |
21 | | -// hasNextStage: (): boolean => { |
22 | | -// const nextPosition: CR.Position = tutorialModel.nextPosition() |
23 | | - |
24 | | -// const sameLevel = nextPosition.levelId === tutorialModel.position.levelId |
25 | | -// const sameStage = nextPosition.stageId === tutorialModel.position.stageId |
26 | | - |
27 | | -// const hasNext: boolean = sameLevel && sameStage |
28 | | - |
29 | | -// console.log('GUARD: hasNextStage', hasNext) |
30 | | -// return hasNext |
31 | | -// }, |
32 | | -// hasNextLevel: (): boolean => { |
33 | | -// const nextPosition: CR.Position = tutorialModel.nextPosition() |
34 | | - |
35 | | -// const sameLevel = nextPosition.levelId === tutorialModel.position.levelId |
36 | | - |
37 | | -// const hasNext: boolean = sameLevel |
38 | | - |
39 | | -// // TODO: ensure this accounts for end |
40 | | -// console.log('GUARD: hasNextLevel', hasNext) |
41 | | -// return hasNext |
42 | | -// }, |
43 | | -// }) |
| 5 | +exportdefault{ |
| 6 | +hasNextStep:(context:CR.MachineContext):boolean=>{ |
| 7 | +const{tutorial, position}=context |
| 8 | +// TODO: protect against errors |
| 9 | +conststeps:G.Step[]=tutorial.version.levels.find((l:G.Level)=>l.id===position.levelId).stages.find((s:G.Stage)=>s.id===position.stageId).steps |
| 10 | + |
| 11 | +// TODO: verify not -1 |
| 12 | +return!(steps.indexOf(position.stepId)===steps.length-1) |
| 13 | +}, |
| 14 | +hasNextStage:(context:CR.MachineContext):boolean=>{ |
| 15 | +const{tutorial, position}=context |
| 16 | +// TODO: protect against errors |
| 17 | +conststages:G.Stage[]=tutorial.version.levels.find((l:G.Level)=>l.id===position.levelId).stages |
| 18 | + |
| 19 | +// TODO: verify not -1 |
| 20 | +return!(stages.indexOf(position.stageId)===stages.length-1) |
| 21 | +}, |
| 22 | +hasNextLevel:(context:CR.MachineContext):boolean=>{ |
| 23 | +const{tutorial, position}=context |
| 24 | +// TODO: protect against errors |
| 25 | +constlevels:G.Level[]=tutorial.version.levels |
| 26 | + |
| 27 | +// TODO: verify not -1 |
| 28 | +return!(levels.indexOf(position.levelId)===levels.length-1) |
| 29 | +}, |
| 30 | +} |