1
1
import { Button , Step } from '@alifd/next'
2
2
import * as React from 'react'
3
- import CR from 'typings'
4
- import CC from '../../../../typings/context'
3
+ import * as T from '../../../../typings/graphql'
5
4
6
5
import Markdown from '../Markdown'
7
6
import LevelStageSummary from './LevelStageSummary'
@@ -25,45 +24,46 @@ const styles = {
25
24
}
26
25
27
26
interface Props {
28
- level : CR . TutorialLevel
29
- stages : {
30
- [ stageId : string ] : any // CC.StageWithStatus
31
- }
27
+ level : T . Level
32
28
onNext ( ) : void
33
29
onBack ( ) : void
34
30
}
35
31
36
- const Level = ( { level, stages, onNext, onBack } : Props ) => {
37
- const { content, stageList } = level
38
- const { title, text } = content
39
- const activeIndex = stageList . findIndex ( ( stageId : string ) => {
40
- return stages [ stageId ] . status . active
41
- } )
42
-
32
+ const Level = ( { level, onNext, onBack } : Props ) => {
33
+ if ( ! level || ! level . stages ) {
34
+ throw new Error ( 'No level stages found' )
35
+ }
36
+ const activeIndex = level . stages . findIndex ( ( stage : T . Stage | null ) => stage && stage . status === 'ACTIVE' ) || 0
43
37
return (
44
38
< div style = { styles . card } >
45
39
< div style = { styles . content } >
46
- < h2 style = { styles . title } > { title } </ h2 >
47
- < Markdown > { text } </ Markdown >
40
+ < h2 style = { styles . title } > { level . title } </ h2 >
41
+ < Markdown > { level . text || '' } </ Markdown >
48
42
</ div >
49
43
< div style = { styles . steps } >
50
44
< Step current = { activeIndex } direction = "ver" animation = { false } >
51
- { stageList . map ( ( stageId : string , index : number ) => {
52
- const stage : CC . StageWithStatus = stages [ stageId ]
53
- const { active } = stage . status
54
- const clickHandler = active ? onNext : ( ) => { }
45
+ { level . stages . map ( ( stage : T . Stage | null , index : number ) => {
46
+ if ( ! stage ) {
47
+ return null
48
+ }
49
+ const active = stage . status === 'ACTIVE'
50
+ const clickHandler = active
51
+ ? onNext
52
+ : ( ) => {
53
+ /* empty */
54
+ }
55
55
// note - must add click handler to title, content & step.item
56
56
// as all are separted components
57
57
return (
58
58
< Step . Item
59
- key = { stageId }
59
+ key = { stage . id }
60
60
style = { { backgroundColor : 'blue' } }
61
61
title = {
62
62
< span className = { active ? 'hover-select' : '' } onClick = { clickHandler } >
63
- { stage . content . title || `Stage ${ index + 1 } ` }
63
+ { stage . title || `Stage ${ index + 1 } ` }
64
64
</ span >
65
65
}
66
- content = { < LevelStageSummary key = { stageId } stage = { stage } onNext = { clickHandler } /> }
66
+ content = { < LevelStageSummary key = { stage . id } stage = { stage } onNext = { clickHandler } /> }
67
67
onClick = { clickHandler }
68
68
/>
69
69
)
0 commit comments