@@ -12,7 +12,7 @@ import BannerSection from '../../components/learn/subject-banner';
12
12
import SyllabusTree from '../../components/learn/syllabus-tree/syllabus-tree-container' ;
13
13
import SubjectMarkdown from '../../components/learn/subject-marked' ;
14
14
15
- import { laravelSyllabus } from '../../utils/mock-data' ;
15
+ import { laravelSyllabus , reactSyllabus } from '../../utils/mock-data' ;
16
16
17
17
const CurriculumSection = styled . section `
18
18
${ baseContainer } ;
@@ -56,21 +56,37 @@ const Fab = styled.div`
56
56
}
57
57
` ;
58
58
59
- const defaultChapter = laravelSyllabus [ 0 ] . chapters [ 0 ] ;
60
-
61
59
export default class Subject extends React . Component {
62
60
constructor ( props ) {
63
61
super ( props ) ;
64
62
this . state = {
63
+ activeSubject : this . selectSubject ( this . props . url . query . id ) ,
65
64
activeChapterContent : '' ,
66
- activeChapterName : defaultChapter . name ,
65
+ activeChapterName :
66
+ this . selectSubject ( this . props . url . query . id ) === null
67
+ ? ''
68
+ : this . selectSubject ( this . props . url . query . id ) [ 0 ] . chapters [ 0 ] . name ,
67
69
loading : true ,
68
70
isSidebarOpen : true ,
69
71
} ;
70
72
}
71
73
74
+ selectSubject ( openedGuide ) {
75
+ switch ( openedGuide ) {
76
+ case 'laravel' :
77
+ return laravelSyllabus ;
78
+ case 'reactjs' :
79
+ return reactSyllabus ;
80
+ default :
81
+ return null ;
82
+ }
83
+ }
84
+
72
85
componentDidMount ( ) {
73
- this . getChapterContent ( defaultChapter ) ;
86
+ if ( this . state . activeSubject !== null ) {
87
+ const defaultChapter = this . state . activeSubject [ 0 ] . chapters [ 0 ] ;
88
+ this . getChapterContent ( defaultChapter ) ;
89
+ }
74
90
}
75
91
76
92
changeChapter = selectedChapter => {
@@ -91,7 +107,11 @@ export default class Subject extends React.Component {
91
107
}
92
108
93
109
render ( ) {
94
- return this . props . url . query . id === 'laravel' ? (
110
+ return this . state . activeSubject === null ? (
111
+ < Layout >
112
+ < Title inverted > Curriculum for { this . props . url . query . id } and others Coming soon!!</ Title >
113
+ </ Layout >
114
+ ) : (
95
115
< Layout >
96
116
< BannerSection
97
117
textInverted
@@ -104,7 +124,7 @@ export default class Subject extends React.Component {
104
124
{ this . state . isSidebarOpen ? (
105
125
< Box width = { [ 0 , 0.2 ] } flex = { '1 1 auto' } className = "box_toc" >
106
126
< div className = "toc_title" > Table of content</ div >
107
- < SyllabusTree data = { laravelSyllabus } changeChapter = { this . changeChapter } />
127
+ < SyllabusTree data = { this . state . activeSubject } changeChapter = { this . changeChapter } />
108
128
</ Box >
109
129
) : null }
110
130
< Box width = { [ 1 , 0.8 ] } flex = { '1 1 auto' } px = { [ 1 , 2 ] } className = "box_content" >
@@ -121,10 +141,6 @@ export default class Subject extends React.Component {
121
141
</ Flex >
122
142
</ CurriculumSection >
123
143
</ Layout >
124
- ) : (
125
- < Layout >
126
- < Title inverted > Curriculum for { this . props . url . query . id } and others Coming soon!!</ Title >
127
- </ Layout >
128
144
) ;
129
145
}
130
146
}
0 commit comments