Skip to content

Commit 85e6463

Browse files
committed
check for first and last elements of array
1 parent 2d129e2 commit 85e6463

File tree

8 files changed

+45
-47
lines changed

8 files changed

+45
-47
lines changed

src/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ function App() {
6464
lessons={courseObj.lessons}
6565
curr_lesson_num={order}
6666
base_path={courseObj.slug}
67-
prev_slug={prevCourse ? prevCourse.slug : null}
68-
next_slug={nextCourse ? nextCourse.slug : null}
67+
prev_slug={prevCourse ? prevCourse.slug : undefined}
68+
next_slug={nextCourse ? nextCourse.slug : undefined}
6969

7070
/>
7171
);

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 LessonNavBar } from './lesson/LessonNavBar';
13+
export { default as LessonNav } from './lesson/LessonNav';
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/CourseNav.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import React from 'react';
22
import { Link } from 'react-router-dom';
33
import PropTypes from 'prop-types';
4-
// import '../../css/lesson/CourseNav.scss';
4+
import '../../css/lesson/LessonNav.scss';
55

6-
const CourseNav = ({prev_slug, next_slug}) => (
6+
const CourseNav = ({prev_path, next_path}) => (
77
<div className="lesson-nav">
8-
{ prev_slug
8+
{ prev_path
99
? <button type="button" className='btn prev-btn'>
10-
<Link to={`/courses/${prev_slug}/0`} >← Prev</Link>
10+
<Link to={prev_path} >← Prev</Link>
1111
</button>
1212
: ''}
13-
{ next_slug
13+
{ next_path
1414
? <button type="button" className="btn next-btn">
15-
<Link to={`/courses/${next_slug}/0`}>Next →</Link>
15+
<Link to={next_path}>Next →</Link>
1616
</button>
1717
: ''}
1818
</div>
1919
);
2020

2121
CourseNav.propTypes = {
22-
prev_slug: PropTypes.string.isRequired,
23-
next_slug: PropTypes.string.isRequired,
22+
prev_path: PropTypes.string.isRequired,
23+
next_path: PropTypes.string.isRequired,
2424
};
2525

2626
export default CourseNav;

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 { LessonNavBar } from '..';
2+
import { LessonNav } 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-
<LessonNavBar order={order} base_path={base_path} course_size={course_size} />
14+
<LessonNav 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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from 'react';
2+
import { Link } from 'react-router-dom';
3+
import PropTypes from 'prop-types';
4+
import '../../css/lesson/LessonNav.scss';
5+
6+
const LessonNav = ({prev_path, next_path}) => (
7+
<div className="lesson-nav">
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+
LessonNav.propTypes = {
22+
prev_path: PropTypes.string.isRequired,
23+
next_path: PropTypes.string.isRequired,
24+
};
25+
26+
export default LessonNav;

src/components/lesson/LessonNavBar.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/components/lesson/LessonsPane.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ 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';
5+
import LessonNav from './CourseNav';
66

77
// TODO: add next and previous course buttons
88
const LessonsPane = ({ course_title, lessons, curr_lesson_num, base_path, prev_slug, next_slug }) => (
99
<div className="lessons-pane">
10-
<LessonNavBar />
10+
<LessonNav prev_path={prev_slug ? `/courses/${prev_slug}/0`: undefined} next_path={next_slug ? `/courses/${next_slug}/0` : undefined} />
1111
<h2>{course_title}</h2>
1212
{lessons.map(({ order, title, length }) => (
1313
<LessonLink
@@ -33,6 +33,8 @@ LessonsPane.propTypes = {
3333
}),
3434
).isRequired,
3535
base_path: PropTypes.string.isRequired,
36+
prev_slug: PropTypes.string.isRequired,
37+
next_slug: PropTypes.string.isRequired,
3638
};
3739

3840
export default LessonsPane;
File renamed without changes.

0 commit comments

Comments
 (0)