@@ -4,7 +4,7 @@ import fetch from 'isomorphic-unfetch';
4
4
import Layout from '../../components/common/layout' ;
5
5
import BannerSection from '../../components/learn/subject-banner' ;
6
6
import SyllabusTree from '../../components/learn/syllabus-tree/syllabus-tree-container' ;
7
- // import MarkedJS from '../../components/common/markedjs';
7
+ import MarkedJS from '../../components/common/markedjs' ;
8
8
9
9
import { laravelSyllabus } from '../../utils/mock-data' ;
10
10
@@ -14,20 +14,31 @@ export default class Subject extends React.Component {
14
14
constructor ( props ) {
15
15
super ( props ) ;
16
16
this . state = {
17
- viewingChapter : defaultChapter ,
17
+ chapterContent : '' ,
18
+ loading : true ,
18
19
} ;
19
20
}
20
21
21
- componentDidMount ( ) { }
22
-
23
- async getChapterContent ( chapter ) {
24
- const responce = await fetch ( chapter ) ;
22
+ componentDidMount ( ) {
23
+ this . getChapterContent ( defaultChapter ) ;
25
24
}
26
25
27
26
changeChapter = selectedChapter => {
28
- this . setState ( { viewingChapter : selectedChapter } ) ;
27
+ this . setState ( {
28
+ loading : true ,
29
+ } ) ;
30
+ this . getChapterContent ( selectedChapter ) ;
29
31
} ;
30
32
33
+ async getChapterContent ( chapter ) {
34
+ const chapterContentPromise = await fetch ( chapter ) ;
35
+ const chapterContent = await chapterContentPromise . text ( ) ;
36
+ await this . setState ( {
37
+ chapterContent,
38
+ loading : false ,
39
+ } ) ;
40
+ }
41
+
31
42
render ( ) {
32
43
return (
33
44
< Layout >
@@ -38,6 +49,7 @@ export default class Subject extends React.Component {
38
49
icon = "devicon-laravel-plain colored"
39
50
/>
40
51
< SyllabusTree data = { laravelSyllabus } changeChapter = { this . changeChapter } />
52
+ < MarkedJS loading = { this . state . loading } markdown = { this . state . chapterContent } />
41
53
</ Layout >
42
54
) ;
43
55
}
0 commit comments