@@ -12,6 +12,7 @@ import ProcessMessages from '../../components/ProcessMessages'
1212import TestMessage from '../../components/TestMessage'
1313import { Progress } from '@alifd/next'
1414import { DISPLAY_RUN_TEST_BUTTON } from '../../environment'
15+ import formatLevels from './formatLevels'
1516
1617const styles = {
1718 header : {
@@ -76,6 +77,12 @@ interface PageProps {
7677 send ( action : T . Action ) : void
7778}
7879
80+ /**
81+ * NOTE: Unused commands
82+ * { type: 'STEP_SOLUTION_LOAD' }
83+ * { type: 'OPEN_LOGS', payload: { channel } }
84+ */
85+
7986const TutorialPage = ( props : PageProps ) => {
8087 const { position, progress, processes, testStatus } = props . context
8188
@@ -90,29 +97,20 @@ const TutorialPage = (props: PageProps) => {
9097 } )
9198 }
9299
93- // const onLoadSolution = (): void => {
94- // props.send({ type: 'STEP_SOLUTION_LOAD' })
95- // }
96-
97100 const onRunTest = ( ) : void => {
98101 props . send ( { type : 'RUN_TEST' } )
99102 }
100103
101- // const onOpenLogs = (channel: string): void => {
102- // props.send({ type: 'OPEN_LOGS', payload: { channel } })
103- // }
104-
105- const levelIndex = tutorial . levels . findIndex ( ( l : TT . Level ) => l . id === position . levelId )
106- const levelStatus = progress . levels [ position . levelId ] ? 'COMPLETE' : 'ACTIVE'
107- const level : TT . Level = tutorial . levels [ levelIndex ]
108104 const [ menuVisible , setMenuVisible ] = React . useState ( false )
109105
110106 const [ page , setPage ] = React . useState < 'level' | 'settings' | 'review' > ( 'level' )
111107
112- let currentStep = level . steps . findIndex ( ( s : TT . Step ) => s . status === 'ACTIVE' )
113- if ( currentStep === - 1 ) {
114- currentStep = level . steps . length
115- }
108+ const { level, levels, stepIndex } = formatLevels ( {
109+ progress,
110+ position,
111+ levels : tutorial . levels ,
112+ testStatus,
113+ } )
116114
117115 return (
118116 < div >
@@ -124,19 +122,9 @@ const TutorialPage = (props: PageProps) => {
124122 < span css = { styles . title } > { tutorial . summary . title } </ span >
125123 </ div >
126124
127- { page === 'level' && (
128- < Level
129- level = { level }
130- currentStep = { currentStep }
131- status = { levelStatus }
132- progress = { progress }
133- position = { position }
134- processes = { processes }
135- testStatus = { testStatus }
136- />
137- ) }
125+ { page === 'level' && < Level level = { level } /> }
138126 { page === 'settings' && < SettingsPage /> }
139- { page === 'review' && < ReviewPage levels = { tutorial . levels } progress = { progress } testStatus = { testStatus } /> }
127+ { page === 'review' && < ReviewPage levels = { levels } /> }
140128 </ div >
141129 < div css = { styles . footer } >
142130 { /* Process Modal */ }
@@ -152,7 +140,7 @@ const TutorialPage = (props: PageProps) => {
152140 </ div >
153141 ) }
154142 { /* Left */ }
155- { DISPLAY_RUN_TEST_BUTTON && levelStatus !== 'COMPLETE' ? (
143+ { DISPLAY_RUN_TEST_BUTTON && level . status !== 'COMPLETE' ? (
156144 < Button style = { { marginLeft : '1rem' } } type = "primary" onClick = { onRunTest } disabled = { processes . length > 0 } >
157145 Run
158146 </ Button >
@@ -165,22 +153,22 @@ const TutorialPage = (props: PageProps) => {
165153
166154 { /* Right */ }
167155 < div >
168- { levelStatus === 'COMPLETE' || ! level . steps . length ? (
156+ { level . status === 'COMPLETE' || ! level . steps . length ? (
169157 < Button type = "primary" onClick = { onContinue } >
170158 Continue
171159 </ Button >
172160 ) : (
173161 < Progress
174162 state = "success"
175163 progressive
176- percent = { ( currentStep / level . steps . length ) * 100 }
164+ percent = { ( stepIndex / level . steps . length ) * 100 }
177165 shape = "line"
178166 color = "rgb(85, 132, 255)"
179167 css = { styles . taskProgress }
180168 textRender = { ( percent : number ) => {
181169 return (
182170 < span style = { { color : 'white' } } >
183- { currentStep } of { level . steps . length }
171+ { stepIndex } of { level . steps . length }
184172 </ span >
185173 )
186174 } }
0 commit comments