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

Commit 3dc8a3b

Browse files
authored
Merge pull request #138 from coderplex/react-guide
react added
2 parents f848c60 + acae377 commit 3dc8a3b

File tree

2 files changed

+188
-160
lines changed

2 files changed

+188
-160
lines changed

Diff for: pages/learn/subject.js

+27-11
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import BannerSection from '../../components/learn/subject-banner';
1212
import SyllabusTree from '../../components/learn/syllabus-tree/syllabus-tree-container';
1313
import SubjectMarkdown from '../../components/learn/subject-marked';
1414

15-
import { laravelSyllabus } from '../../utils/mock-data';
15+
import { laravelSyllabus, reactSyllabus } from '../../utils/mock-data';
1616

1717
const CurriculumSection = styled.section`
1818
${baseContainer};
@@ -56,21 +56,37 @@ const Fab = styled.div`
5656
}
5757
`;
5858

59-
const defaultChapter = laravelSyllabus[0].chapters[0];
60-
6159
export default class Subject extends React.Component {
6260
constructor(props) {
6361
super(props);
6462
this.state = {
63+
activeSubject: this.selectSubject(this.props.url.query.id),
6564
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,
6769
loading: true,
6870
isSidebarOpen: true,
6971
};
7072
}
7173

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+
7285
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+
}
7490
}
7591

7692
changeChapter = selectedChapter => {
@@ -91,7 +107,11 @@ export default class Subject extends React.Component {
91107
}
92108

93109
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+
) : (
95115
<Layout>
96116
<BannerSection
97117
textInverted
@@ -104,7 +124,7 @@ export default class Subject extends React.Component {
104124
{this.state.isSidebarOpen ? (
105125
<Box width={[0, 0.2]} flex={'1 1 auto'} className="box_toc">
106126
<div className="toc_title">Table of content</div>
107-
<SyllabusTree data={laravelSyllabus} changeChapter={this.changeChapter} />
127+
<SyllabusTree data={this.state.activeSubject} changeChapter={this.changeChapter} />
108128
</Box>
109129
) : null}
110130
<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 {
121141
</Flex>
122142
</CurriculumSection>
123143
</Layout>
124-
) : (
125-
<Layout>
126-
<Title inverted>Curriculum for {this.props.url.query.id} and others Coming soon!!</Title>
127-
</Layout>
128144
);
129145
}
130146
}

0 commit comments

Comments
 (0)