@@ -12,12 +12,14 @@ const styles = {
1212 page : {
1313 backgroundColor : 'white' ,
1414 position : 'relative' as 'relative' ,
15+ height : 'auto' ,
16+ width : '100%' ,
17+ } ,
18+ content : {
1519 display : 'flex' as 'flex' ,
1620 flexDirection : 'column' as 'column' ,
1721 padding : 0 ,
1822 paddingBottom : '5rem' ,
19- height : 'auto' ,
20- width : '100%' ,
2123 } ,
2224 header : {
2325 height : '2rem' ,
@@ -26,13 +28,11 @@ const styles = {
2628 lineHeight : '1rem' ,
2729 padding : '10px 1rem' ,
2830 } ,
29- content : {
31+ text : {
3032 padding : '0rem 1rem' ,
3133 paddingBottom : '1rem' ,
3234 } ,
33- tasks : {
34- paddingBottom : '5rem' ,
35- } ,
35+ tasks : { } ,
3636 steps : {
3737 padding : '1rem 1rem' ,
3838 } ,
@@ -85,8 +85,10 @@ interface Props {
8585}
8686
8787const Level = ( { level, onContinue, onLoadSolution, processes, testStatus } : Props ) => {
88- if ( ! level . steps ) {
89- throw new Error ( 'No Stage steps found' )
88+ // @ts -ignore
89+ let currentStep = level . steps . findIndex ( s => s . status === 'ACTIVE' )
90+ if ( currentStep === - 1 ) {
91+ currentStep = level . steps . length
9092 }
9193
9294 const pageBottomRef = React . useRef ( null )
@@ -95,70 +97,70 @@ const Level = ({ level, onContinue, onLoadSolution, processes, testStatus }: Pro
9597 // @ts -ignore
9698 pageBottomRef . current . scrollIntoView ( { behavior : 'smooth' } )
9799 }
98- // @ts -ignore
99- let currentStep = level . steps . findIndex ( s => s . status === 'ACTIVE' )
100- if ( currentStep === - 1 ) {
101- currentStep = level . steps . length
102- }
103100 React . useEffect ( scrollToBottom , [ currentStep ] )
104101
105102 return (
106103 < div css = { styles . page } >
107- < div css = { styles . header } >
108- < span > Learn</ span >
109- </ div >
110104 < div css = { styles . content } >
111- < h2 css = { styles . title } > { level . title } </ h2 >
112- < Markdown > { level . content || '' } </ Markdown >
113- </ div >
114-
115- < div css = { styles . tasks } >
116- < div css = { styles . header } > Tasks</ div >
117- < div css = { styles . steps } >
118- { level . steps . map ( ( step : ( G . Step & { status : T . ProgressStatus } ) | null , index : number ) => {
119- if ( ! step ) {
120- return null
121- }
122- return (
123- < Step
124- key = { step . id }
125- order = { index + 1 }
126- status = { step . status }
127- content = { step . content }
128- onLoadSolution = { onLoadSolution }
129- />
130- )
131- } ) }
105+ < div css = { styles . header } >
106+ < span > Learn</ span >
107+ </ div >
108+ < div css = { styles . text } >
109+ < h2 css = { styles . title } > { level . title } </ h2 >
110+ < Markdown > { level . content || '' } </ Markdown >
132111 </ div >
112+
113+ { level . steps . length ? (
114+ < div css = { styles . tasks } >
115+ < div css = { styles . header } > Tasks</ div >
116+ < div css = { styles . steps } >
117+ { level . steps . map ( ( step : ( G . Step & { status : T . ProgressStatus } ) | null , index : number ) => {
118+ if ( ! step ) {
119+ return null
120+ }
121+ return (
122+ < Step
123+ key = { step . id }
124+ order = { index + 1 }
125+ status = { step . status }
126+ content = { step . content }
127+ onLoadSolution = { onLoadSolution }
128+ />
129+ )
130+ } ) }
131+ </ div >
132+ </ div >
133+ ) : null }
134+
133135 < div ref = { pageBottomRef } />
134- </ div >
135136
136- { ( testStatus || processes . length > 0 ) && (
137- < div css = { styles . processes } >
138- < ProcessMessages processes = { processes } testStatus = { testStatus } />
139- </ div >
140- ) }
137+ { ( testStatus || processes . length > 0 ) && (
138+ < div css = { styles . processes } >
139+ < ProcessMessages processes = { processes } testStatus = { testStatus } />
140+ </ div >
141+ ) }
141142
142- < div css = { styles . nux } >
143- < NuxTutorial onLoadSolution = { onLoadSolution } />
144- </ div >
143+ < div css = { styles . nux } >
144+ < NuxTutorial onLoadSolution = { onLoadSolution } />
145+ </ div >
145146
146- < div css = { styles . footer } >
147- < span >
148- { typeof level . index === 'number' ? `${ level . index + 1 } . ` : '' }
149- { level . title }
150- </ span >
151- < span >
152- { level . status === 'COMPLETE' ? (
153- < Button type = "primary" onClick = { onContinue } >
154- Continue
155- </ Button >
156- ) : (
157- < span css = { styles . taskCount } >
158- { currentStep } of { level . steps . length } tasks
159- </ span >
160- ) }
161- </ span >
147+ < div css = { styles . footer } >
148+ < span >
149+ { typeof level . index === 'number' ? `${ level . index + 1 } . ` : '' }
150+ { level . title }
151+ </ span >
152+ < span >
153+ { level . status === 'COMPLETE' || ! level . steps . length ? (
154+ < Button type = "primary" onClick = { onContinue } >
155+ Continue
156+ </ Button >
157+ ) : (
158+ < span css = { styles . taskCount } >
159+ { currentStep } of { level . steps . length } tasks
160+ </ span >
161+ ) }
162+ </ span >
163+ </ div >
162164 </ div >
163165 </ div >
164166 )
0 commit comments