@@ -2,12 +2,8 @@ import * as React from 'react'
22import * as T from 'typings'
33import * as TT from 'typings/tutorial'
44import { css , jsx } from '@emotion/core'
5- import Button from '../../../components/Button'
65import Markdown from '../../../components/Markdown'
7- import ProcessMessages from '../../../components/ProcessMessages'
8- import TestMessage from '../../../components/TestMessage'
96import Step from './Step'
10- import { DISPLAY_RUN_TEST_BUTTON } from '../../../environment'
117
128const styles = {
139 page : {
@@ -40,46 +36,11 @@ const styles = {
4036 fontWeight : 'bold' as 'bold' ,
4137 lineHeight : '1.2rem' ,
4238 } ,
43- processes : {
44- padding : '0 1rem' ,
45- position : 'fixed' as 'fixed' ,
46- bottom : '2rem' ,
47- left : 0 ,
48- right : 0 ,
49- top : 'auto' ,
50- } ,
51- testMessage : {
52- position : 'absolute' as 'absolute' ,
53- top : 'auto' ,
54- bottom : '2rem' ,
55- left : '5px' ,
56- right : '5px' ,
57- } ,
58- footer : {
59- display : 'flex' as 'flex' ,
60- flexDirection : 'row' as 'row' ,
61- justifyContent : 'space-between' ,
62- alignItems : 'center' ,
63- height : '2rem' ,
64- backgroundColor : 'black' ,
65- fontSize : '1rem' ,
66- lineHeight : '1rem' ,
67- padding : '10px 1rem' ,
68- position : 'fixed' as 'fixed' ,
69- bottom : 0 ,
70- left : 0 ,
71- right : 0 ,
72- color : 'white' ,
73- } ,
74- taskCount : {
75- fontSize : '0.8rem' ,
76- opacity : 0.9 ,
77- } ,
7839}
7940
8041interface Props {
81- tutorial : Exclude < TT . Tutorial , 'config' >
82- index : number
42+ level : TT . Level
43+ currentStep : number
8344 status : 'COMPLETE' | 'ACTIVE' | 'INCOMPLETE'
8445 progress : T . Progress
8546 position : T . Position
@@ -91,21 +52,7 @@ interface Props {
9152 onOpenLogs ( channel : string ) : void
9253}
9354
94- const Level = ( {
95- tutorial,
96- index,
97- status,
98- progress,
99- position,
100- onContinue,
101- onRunTest,
102- onLoadSolution,
103- onOpenLogs,
104- processes,
105- testStatus,
106- } : Props ) => {
107- const level : TT . Level = tutorial . levels [ index ]
108-
55+ const Level = ( { level, progress, position, onLoadSolution, currentStep, testStatus } : Props ) => {
10956 // hold state for hints for the level
11057 const [ displayHintsIndex , setDisplayHintsIndex ] = React . useState < number [ ] > ( [ ] )
11158 const setHintsIndex = ( index : number , value : number ) => {
@@ -117,10 +64,10 @@ const Level = ({
11764 }
11865 React . useEffect ( ( ) => {
11966 // set the hints to empty on level starts
120- setDisplayHintsIndex ( steps . map ( ( s ) => - 1 ) )
67+ setDisplayHintsIndex ( level . steps . map ( ( s : TT . Step ) => - 1 ) )
12168 } , [ position . levelId ] )
12269
123- const steps : Array < TT . Step & { status : T . ProgressStatus } > = level . steps . map ( ( step : TT . Step ) => {
70+ const steps : TT . Step [ ] = level . steps . map ( ( step : TT . Step ) => {
12471 // label step status for step component
12572 let status : T . ProgressStatus = 'INCOMPLETE'
12673 if ( progress . steps [ step . id ] ) {
@@ -132,10 +79,6 @@ const Level = ({
13279 } )
13380
13481 // current
135- let currentStep = steps . findIndex ( ( s ) => s . status === 'ACTIVE' )
136- if ( currentStep === - 1 ) {
137- currentStep = steps . length
138- }
13982
14083 const pageBottomRef = React . useRef ( null )
14184 const scrollToBottom = ( ) => {
@@ -159,7 +102,7 @@ const Level = ({
159102 { steps . length ? (
160103 < div css = { styles . tasks } >
161104 < div css = { styles . steps } >
162- { steps . map ( ( step : ( TT . Step & { status : T . ProgressStatus } ) | null , stepIndex : number ) => {
105+ { steps . map ( ( step : TT . Step | null , stepIndex : number ) => {
163106 if ( ! step ) {
164107 return null
165108 }
@@ -173,8 +116,7 @@ const Level = ({
173116 return (
174117 < Step
175118 key = { step . id }
176- index = { index }
177- status = { step . status }
119+ status = { step . status || 'INCOMPLETE' }
178120 content = { step . content }
179121 onLoadSolution = { onLoadSolution }
180122 subtasks = { subtasks }
@@ -189,38 +131,6 @@ const Level = ({
189131 ) : null }
190132
191133 < div ref = { pageBottomRef } />
192-
193- < div css = { styles . footer } >
194- { /* Process Modal */ }
195- { processes . length > 0 && (
196- < div css = { styles . processes } >
197- < ProcessMessages processes = { processes } />
198- </ div >
199- ) }
200- { /* Test Fail Modal */ }
201- { testStatus && testStatus . type === 'warning' && (
202- < div css = { styles . testMessage } >
203- < TestMessage message = { testStatus . title } />
204- </ div >
205- ) }
206-
207- { DISPLAY_RUN_TEST_BUTTON && status !== 'COMPLETE' ? (
208- < Button type = "primary" onClick = { onRunTest } disabled = { processes . length > 0 } >
209- Run
210- </ Button >
211- ) : null }
212- < span >
213- { status === 'COMPLETE' || ! steps . length ? (
214- < Button type = "primary" onClick = { onContinue } >
215- Continue
216- </ Button >
217- ) : (
218- < span css = { styles . taskCount } >
219- { currentStep } of { steps . length } tasks
220- </ span >
221- ) }
222- </ span >
223- </ div >
224134 </ div >
225135 </ div >
226136 )
0 commit comments