Skip to content

Commit b67e460

Browse files
authored
Merge pull request #80 from talent-path-pipeline/66-course-nav
66 course nav
2 parents 938b5be + 374e607 commit b67e460

File tree

8 files changed

+95
-49
lines changed

8 files changed

+95
-49
lines changed

src/App.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ function App() {
5353
const courseObj = courses.find(
5454
course => course.slug === props.match.params.course,
5555
);
56+
const prevCourse = courses.find(course => course.order === courseObj.order - 1);
57+
const nextCourse = courses.find(course => course.order === courseObj.order + 1);
5658
const order = parseInt(props.match.params.order, 10);
5759
if (!courseObj || order >= courseObj.lessons.length) return <ErrorPage />;
5860
return (
@@ -62,6 +64,9 @@ function App() {
6264
lessons={courseObj.lessons}
6365
curr_lesson_num={order}
6466
base_path={courseObj.slug}
67+
prev_slug={prevCourse ? prevCourse.slug : undefined}
68+
next_slug={nextCourse ? nextCourse.slug : undefined}
69+
6570
/>
6671
);
6772
}}

src/components/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export { default as CourseInfo } from './course/CourseInfo';
1010
// ========================================
1111
// lesson
1212
export { default as LessonInfo } from './lesson/LessonInfo';
13-
export { default as LessonNav } from './lesson/LessonNav';
13+
export { default as LessonNavBar } from './lesson/LessonNavBar';
1414
export { default as LessonVideo } from './lesson/LessonVideo';
1515
export { default as LessonLink } from './lesson/LessonLink';
1616
export { default as LessonsPane } from './lesson/LessonsPane';

src/components/lesson/LessonInfo.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import React from 'react';
2-
import { LessonNav } from '..';
2+
import { LessonNavBar } from '..';
33
import PropTypes from 'prop-types';
44
import '../../css/lesson/LessonInfo.scss';
55

66
const getVideoURL = embedLink => embedLink.replace('embed/', 'watch?v=');
77

88
const LessonInfo = ({ lesson, base_path, course_size }) => {
99
const {title, description, order, src, yt_chan_name, yt_chan_src, yt_title, yt_desc} = lesson;
10-
10+
const prevPath = order ? `/courses/${base_path}/${order - 1}` : undefined;
11+
const nextPath = order < course_size - 1 ? `/courses/${base_path}/${order + 1}` : undefined;
1112
return (
1213
<div className="lesson-info">
13-
<LessonNav order={order} base_path={base_path} course_size={course_size} />
14+
<LessonNavBar className="lesson-nav" order={order} base_path={base_path} course_size={course_size} prev_path={prevPath} next_path={nextPath} />
1415
<h4 id="lesson-playing">Now playing:</h4>
1516
<h2>{title || 'Lesson'}</h2>
1617
<hr />

src/components/lesson/LessonNav.js

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
import { Link } from 'react-router-dom';
3+
import PropTypes from 'prop-types';
4+
import '../../css/lesson/LessonNavBar.scss';
5+
6+
const LessonNavBar = ({prev_path, next_path, className}) => (
7+
<div className={`lesson-nav-bar ${className}`}>
8+
{ prev_path
9+
? <button type="button" className='btn prev-btn'>
10+
<Link to={prev_path} >← Prev</Link>
11+
</button>
12+
: ''}
13+
{ next_path
14+
? <button type="button" className="btn next-btn">
15+
<Link to={next_path}>Next →</Link>
16+
</button>
17+
: ''}
18+
</div>
19+
);
20+
21+
LessonNavBar.propTypes = {
22+
prev_path: PropTypes.string,
23+
next_path: PropTypes.string,
24+
className: PropTypes.string.isRequired,
25+
};
26+
27+
LessonNavBar.defaultProps = {
28+
prev_path: '',
29+
next_path: '',
30+
};
31+
32+
export default LessonNavBar;

src/components/lesson/LessonsPane.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import { LessonLink } from '..';
44
import '../../css/lesson/LessonsPane.scss';
5+
import LessonNavBar from './LessonNavBar';
56

6-
// TODO: add next and previous course buttons
7-
const LessonsPane = ({ course_title, lessons, curr_lesson_num, base_path }) => (
7+
const LessonsPane = ({ course_title, lessons, curr_lesson_num, base_path, prev_slug, next_slug }) => (
88
<div className="lessons-pane">
9-
<h2>{course_title}</h2>
9+
<h2>
10+
<LessonNavBar className="course-nav" prev_path={prev_slug ? `/courses/${prev_slug}/0`: ''} next_path={next_slug ? `/courses/${next_slug}/0` : ''} />
11+
{course_title}
12+
</h2>
1013
{lessons.map(({ order, title, length }) => (
1114
<LessonLink
1215
key={order}
@@ -31,6 +34,12 @@ LessonsPane.propTypes = {
3134
}),
3235
).isRequired,
3336
base_path: PropTypes.string.isRequired,
37+
prev_slug: PropTypes.string,
38+
next_slug: PropTypes.string,
3439
};
3540

41+
LessonsPane.defaultProps = {
42+
prev_slug: '',
43+
next_slug: '',
44+
};
3645
export default LessonsPane;

src/components/pages/LessonPage.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Lesson, LessonsPane } from '..';
44
import '../../css/pages/LessonPage.scss';
55

66
function LessonPage(props) {
7-
const { curr_lesson_num, lessons, base_path, course_title } = props;
7+
const { curr_lesson_num, lessons, base_path } = props;
88
// const { title, src, description, id } = lessons.find(elem => elem.id === activeId);
99
const lesson = lessons[curr_lesson_num];
1010
const total = lessons.length;
@@ -13,10 +13,7 @@ function LessonPage(props) {
1313
<div className="lesson-page">
1414
<Lesson lesson={lesson} course_size={total} base_path={base_path}/>
1515
<LessonsPane
16-
course_title={course_title}
17-
lessons={lessons}
18-
curr_lesson_num={curr_lesson_num}
19-
base_path={base_path}
16+
{...props}
2017
/>
2118
</div>
2219
);
@@ -35,6 +32,13 @@ LessonPage.propTypes = {
3532
}),
3633
).isRequired,
3734
base_path: PropTypes.string.isRequired,
35+
prev_slug: PropTypes.string,
36+
next_slug: PropTypes.string,
37+
};
38+
39+
LessonPage.defaultProps = {
40+
prev_slug: '',
41+
next_slug: '',
3842
};
3943

4044
export default LessonPage;

src/css/lesson/LessonNav.scss renamed to src/css/lesson/LessonNavBar.scss

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1-
.lesson-nav {
2-
margin-top: -1rem;
3-
margin-bottom: 2rem;
4-
1+
.lesson-nav-bar {
52
.btn {
63
border: none;
74

85
a {
96
font-family: var(--fontfamily);
10-
background-color: var(--navy);
117
font-size: 1rem;
128
height: 100%;
139
width: 100%;
10+
background-color: var(--navy);
1411
color:var(--cream);
1512
text-decoration: none;
16-
padding: 0.75rem 1.5rem;
17-
}
1813

19-
a:hover {
20-
background-color: var(--brown);
2114
}
2215
}
2316

@@ -30,7 +23,36 @@
3023
}
3124
}
3225

33-
.lesson-nav:after {
26+
.lesson-nav {
27+
margin-top: -1rem;
28+
margin-bottom: 2rem;
29+
30+
a {
31+
background-color: var(--navy);
32+
color:var(--cream);
33+
padding: 0.75rem 1.5rem;
34+
}
35+
& a:hover {
36+
background-color: var(--brown);
37+
}
38+
}
39+
40+
.course-nav {
41+
margin-bottom: 1rem;
42+
a {
43+
display: inline-block;
44+
padding: 0.75rem 0;
45+
}
46+
a:hover {
47+
text-decoration: underline;
48+
}
49+
}
50+
51+
52+
53+
54+
// clear floats
55+
.lesson-nav-bar:after {
3456
content: '';
3557
display: block;
3658
clear: both;

0 commit comments

Comments
 (0)