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 7ad04b0

Browse files
author
z
committed
1. width changes to cards in learn
2. marked js file 3. minor changes in tree comp
1 parent 3352b45 commit 7ad04b0

File tree

6 files changed

+244
-42
lines changed

6 files changed

+244
-42
lines changed

components/common/markedjs.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React from 'react';
2+
import marked from 'marked';
3+
import styled from 'react-emotion';
4+
5+
const Marked = styled.div`
6+
background-color: #fff;
7+
`;
8+
9+
export default class MarkedJS extends React.Component {
10+
constructor(props) {
11+
super(props);
12+
marked.setOptions({
13+
renderer: new marked.Renderer(),
14+
gfm: true,
15+
tables: true,
16+
breaks: false,
17+
pedantic: false,
18+
sanitize: true,
19+
smartLists: true,
20+
smartypants: false,
21+
});
22+
}
23+
24+
render() {
25+
return (
26+
<div>
27+
{this.props.loading ? (
28+
<div>Loading...</div>
29+
) : (
30+
<Marked
31+
dangerouslySetInnerHTML={{
32+
__html: marked(this.props.markdown),
33+
}}
34+
/>
35+
)}
36+
</div>
37+
);
38+
}
39+
}

components/learn/subject-card.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ import { breakpoints, Button } from '../../utils/base.styles';
1111
const SubjectCard = styled.div`
1212
${space};
1313
text-decoration: none;
14-
width: calc(25% - 40px);
15-
margin-top: 20px;
16-
margin-bottom: 20px;
14+
width: calc(25% - 24px);
15+
margin-top: 24px;
1716
display: inline-block;
1817
min-height: 200px;
1918
border: 1px solid #b9b9b9;
@@ -63,10 +62,10 @@ const SubjectCard = styled.div`
6362
text-align: center;
6463
}
6564
${breakpoints.md} {
66-
width: calc(50% - 40px);
65+
width: calc(33% - 30px);
6766
}
6867
${breakpoints.sm} {
69-
width: calc(50% - 40px);
68+
width: calc(50% - 50px);
7069
margin: 20px auto;
7170
}
7271
${breakpoints.xs} {

components/learn/syllabus-tree/syllabus-tree-component.js

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import React from 'react';
2-
import PropTypes from 'prop-types';
32
import styled from 'react-emotion';
43

54
export default class TreeView extends React.PureComponent {
65
state = {
76
collapsed: this.props.defaultCollapsed,
87
};
98

10-
handleClick = (...args) => {
9+
handleNodeClick = (...args) => {
1110
this.setState({ collapsed: !this.state.collapsed });
1211
if (this.props.onClick) {
1312
this.props.onClick(...args);
@@ -21,10 +20,8 @@ export default class TreeView extends React.PureComponent {
2120
itemClassName = '',
2221
treeViewClassName = '',
2322
childrenClassName = '',
24-
nodeLabel,
2523
children,
2624
defaultCollapsed,
27-
...rest
2825
} = this.props;
2926

3027
const Container = styled.div`
@@ -76,28 +73,18 @@ export default class TreeView extends React.PureComponent {
7673
containerClassName += ' tree-view_children-collapsed';
7774
}
7875

79-
const arrow = <div {...rest} className={className + ' ' + arrowClassName} onClick={this.handleClick} />;
76+
const arrow = <div className={`${className} ${arrowClassName}`} onClick={this.handleNodeClick} />;
8077

8178
return (
8279
<Container>
83-
<div className={'tree-view ' + treeViewClassName}>
84-
<div className={'tree-view_item ' + itemClassName}>
80+
<div className={`tree-view ${treeViewClassName}`}>
81+
<div className={`tree-view_item ${itemClassName}`}>
8582
{arrow}
86-
{nodeLabel}
83+
{this.props.nodeLabel}
8784
</div>
88-
<div className={containerClassName + ' ' + childrenClassName}>{collapsed ? null : children}</div>
85+
<div className={`${containerClassName} ${childrenClassName}`}>{collapsed ? null : children}</div>
8986
</div>
9087
</Container>
9188
);
9289
}
9390
}
94-
95-
TreeView.propTypes = {
96-
collapsed: PropTypes.bool,
97-
defaultCollapsed: PropTypes.bool,
98-
nodeLabel: PropTypes.node.isRequired,
99-
className: PropTypes.string,
100-
itemClassName: PropTypes.string,
101-
childrenClassName: PropTypes.string,
102-
treeViewClassName: PropTypes.string,
103-
};

components/learn/syllabus-tree/syllabus-tree-container.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,49 +20,50 @@ export default class SyllabusTree extends React.Component {
2020

2121
render() {
2222
const Container = styled.div`
23-
.node {
23+
& .node {
2424
transition: all 0.5s;
2525
border-radius: 3px;
2626
}
2727
28-
.node:hover {
28+
& .node:hover,
29+
& .info:hover {
2930
background-color: rgb(220, 245, 243);
3031
cursor: pointer;
3132
}
3233
33-
.info,
34-
.node {
34+
& .info,
35+
& .node {
3536
padding: 2px 10px 2px 5px;
3637
font: 14px Helvetica, Arial, sans-serif;
3738
user-select: none;
3839
}
3940
40-
.tree-view_arrow {
41+
& .tree-view_arrow {
4142
transition: all 0.1s;
4243
}
4344
44-
.tree-view_arrow-empty {
45+
& .tree-view_arrow-empty {
4546
color: yellow;
4647
}
4748
`;
4849

4950
return (
5051
<Container>
5152
{this.props.data.map((node, i) => {
52-
const ChapterTitle = (
53-
<span className="node" onClick={() => this.handleClick(i)}>
54-
Type {i}
53+
const UnitTitle = (
54+
<span className="node" key={node.unit.num} onClick={() => this.handleClick(i)}>
55+
{node.unit.name}
5556
</span>
5657
);
5758
return (
5859
<TreeView
5960
key={i}
60-
nodeLabel={ChapterTitle}
61+
nodeLabel={UnitTitle}
6162
collapsed={this.state.nodeStateTracker[i]}
6263
onClick={() => this.handleClick(i)}>
63-
{node.map(entry => (
64-
<div className="info" key={entry.id} onClick={() => console.log(entry.url)}>
65-
{entry.id}
64+
{node.chapters.map(chapter => (
65+
<div className="info" key={chapter.url} onClick={() => this.props.changeChapter(chapter.url)}>
66+
{chapter.name}
6667
</div>
6768
))}
6869
</TreeView>

pages/learn/subject.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
11
import React from 'react';
2+
import fetch from 'isomorphic-unfetch';
23

34
import Layout from '../../components/common/layout';
45
import BannerSection from '../../components/learn/subject-banner';
56
import SyllabusTree from '../../components/learn/syllabus-tree/syllabus-tree-container';
7+
// import MarkedJS from '../../components/common/markedjs';
68

7-
const dataSource = [[{ id: 'aa', url: 'https//:aaple.com' }, { id: 'oo' }], [{ id: 'ff' }]];
9+
import { laravelSyllabus } from '../../utils/mock-data';
10+
11+
const defaultChapter = laravelSyllabus[0].chapters[0].url;
812

913
export default class Subject extends React.Component {
14+
constructor(props) {
15+
super(props);
16+
this.state = {
17+
viewingChapter: defaultChapter,
18+
};
19+
}
20+
21+
componentDidMount() {}
22+
23+
async getChapterContent(chapter) {
24+
const responce = await fetch(chapter);
25+
}
26+
27+
changeChapter = selectedChapter => {
28+
this.setState({ viewingChapter: selectedChapter });
29+
};
30+
1031
render() {
1132
return (
1233
<Layout>
@@ -16,7 +37,7 @@ export default class Subject extends React.Component {
1637
subTitle="Web Development"
1738
icon="devicon-laravel-plain colored"
1839
/>
19-
<SyllabusTree data={dataSource} />
40+
<SyllabusTree data={laravelSyllabus} changeChapter={this.changeChapter} />
2041
</Layout>
2142
);
2243
}

0 commit comments

Comments
 (0)