Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Mar 9, 2021. It is now read-only.

Commit 326de94

Browse files
author
z
committed
functionality of subject page done with out styling
1 parent 12cd83c commit 326de94

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

pages/learn/subject.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import fetch from 'isomorphic-unfetch';
44
import Layout from '../../components/common/layout';
55
import BannerSection from '../../components/learn/subject-banner';
66
import SyllabusTree from '../../components/learn/syllabus-tree/syllabus-tree-container';
7-
// import MarkedJS from '../../components/common/markedjs';
7+
import MarkedJS from '../../components/common/markedjs';
88

99
import { laravelSyllabus } from '../../utils/mock-data';
1010

@@ -14,20 +14,31 @@ export default class Subject extends React.Component {
1414
constructor(props) {
1515
super(props);
1616
this.state = {
17-
viewingChapter: defaultChapter,
17+
chapterContent: '',
18+
loading: true,
1819
};
1920
}
2021

21-
componentDidMount() {}
22-
23-
async getChapterContent(chapter) {
24-
const responce = await fetch(chapter);
22+
componentDidMount() {
23+
this.getChapterContent(defaultChapter);
2524
}
2625

2726
changeChapter = selectedChapter => {
28-
this.setState({ viewingChapter: selectedChapter });
27+
this.setState({
28+
loading: true,
29+
});
30+
this.getChapterContent(selectedChapter);
2931
};
3032

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+
3142
render() {
3243
return (
3344
<Layout>
@@ -38,6 +49,7 @@ export default class Subject extends React.Component {
3849
icon="devicon-laravel-plain colored"
3950
/>
4051
<SyllabusTree data={laravelSyllabus} changeChapter={this.changeChapter} />
52+
<MarkedJS loading={this.state.loading} markdown={this.state.chapterContent} />
4153
</Layout>
4254
);
4355
}

0 commit comments

Comments
 (0)