Skip to content

Commit 2f01e8a

Browse files
authored
Refactor containers to share more code (#61)
Specifically, make sure that the header, footer, and tabs are all shared code so that they look the same and don't need to be redefined as we add more tab pages.
1 parent 589db93 commit 2f01e8a

19 files changed

+290
-241
lines changed

LICENSE

100755100644
File mode changed.

Makefile

100755100644
File mode changed.

src/course-header/CourseTabsNavigation.jsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
4-
import { getConfig } from '@edx/frontend-platform';
54
import classNames from 'classnames';
65

76
import messages from './messages';
87
import Tabs from '../tabs/Tabs';
98

109
function CourseTabsNavigation({
11-
activeTabSlug, tabs, intl,
10+
activeTabSlug, className, tabs, intl,
1211
}) {
1312
return (
14-
<div className="course-tabs-navigation">
13+
<div className={classNames('course-tabs-navigation', className)}>
1514
<div className="container-fluid">
1615
<Tabs
1716
className="nav-underline-tabs"
@@ -21,7 +20,7 @@ function CourseTabsNavigation({
2120
<a
2221
key={slug}
2322
className={classNames('nav-item flex-shrink-0 nav-link', { active: slug === activeTabSlug })}
24-
href={`${getConfig().LMS_BASE_URL}${url}`}
23+
href={url}
2524
>
2625
{title}
2726
</a>
@@ -34,6 +33,7 @@ function CourseTabsNavigation({
3433

3534
CourseTabsNavigation.propTypes = {
3635
activeTabSlug: PropTypes.string,
36+
className: PropTypes.string,
3737
tabs: PropTypes.arrayOf(PropTypes.shape({
3838
title: PropTypes.string.isRequired,
3939
priority: PropTypes.number.isRequired,
@@ -45,6 +45,7 @@ CourseTabsNavigation.propTypes = {
4545

4646
CourseTabsNavigation.defaultProps = {
4747
activeTabSlug: undefined,
48+
className: null,
4849
};
4950

5051
export default injectIntl(CourseTabsNavigation);

src/course-header/Header.jsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@ export default function Header({
6868
}
6969

7070
Header.propTypes = {
71-
courseOrg: PropTypes.string.isRequired,
72-
courseNumber: PropTypes.string.isRequired,
73-
courseTitle: PropTypes.string.isRequired,
71+
courseOrg: PropTypes.string,
72+
courseNumber: PropTypes.string,
73+
courseTitle: PropTypes.string,
74+
};
75+
76+
Header.defaultProps = {
77+
courseOrg: null,
78+
courseNumber: null,
79+
courseTitle: null,
7480
};

src/course-home/CourseHome.jsx

+36-61
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import React from 'react';
2-
import PropTypes from 'prop-types';
2+
import { useSelector } from 'react-redux';
33
import { Button } from '@edx/paragon';
44

55
import { AlertList } from '../user-messages';
6-
import { Header, CourseTabsNavigation } from '../course-header';
7-
import { useLogistrationAlert } from '../logistration-alert';
8-
import { useEnrollmentAlert } from '../enrollment-alert';
96

107
import CourseDates from './CourseDates';
118
import Section from './Section';
@@ -18,80 +15,58 @@ import { useModel } from '../model-store';
1815
const { EnrollmentAlert, StaffEnrollmentAlert } = React.lazy(() => import('../enrollment-alert'));
1916
const LogistrationAlert = React.lazy(() => import('../logistration-alert'));
2017

21-
export default function CourseHome({
22-
courseId,
23-
}) {
24-
useLogistrationAlert();
25-
useEnrollmentAlert(courseId);
18+
export default function CourseHome() {
19+
const {
20+
courseId,
21+
} = useSelector(state => state.courseware);
2622

2723
const {
28-
org,
29-
number,
3024
title,
3125
start,
3226
end,
3327
enrollmentStart,
3428
enrollmentEnd,
3529
enrollmentMode,
3630
isEnrolled,
37-
tabs,
3831
sectionIds,
3932
} = useModel('courses', courseId);
4033

4134
return (
4235
<>
43-
<Header
44-
courseOrg={org}
45-
courseNumber={number}
46-
courseTitle={title}
36+
<AlertList
37+
topic="outline"
38+
className="mb-3"
39+
customAlerts={{
40+
clientEnrollmentAlert: EnrollmentAlert,
41+
clientStaffEnrollmentAlert: StaffEnrollmentAlert,
42+
clientLogistrationAlert: LogistrationAlert,
43+
}}
4744
/>
48-
<main className="d-flex flex-column flex-grow-1">
49-
<div className="container-fluid">
50-
<CourseTabsNavigation tabs={tabs} className="mb-3" activeTabSlug="courseware" />
51-
<AlertList
52-
topic="outline"
53-
className="mb-3"
54-
customAlerts={{
55-
clientEnrollmentAlert: EnrollmentAlert,
56-
clientStaffEnrollmentAlert: StaffEnrollmentAlert,
57-
clientLogistrationAlert: LogistrationAlert,
58-
}}
59-
/>
45+
<div className="d-flex justify-content-between mb-3">
46+
<h2>{title}</h2>
47+
<Button className="btn-primary" type="button">Resume Course</Button>
48+
</div>
49+
<div className="row">
50+
<div className="col col-8">
51+
{sectionIds.map((sectionId) => (
52+
<Section
53+
key={sectionId}
54+
id={sectionId}
55+
courseId={courseId}
56+
/>
57+
))}
6058
</div>
61-
<div className="flex-grow-1">
62-
<div className="container-fluid">
63-
<div className="d-flex justify-content-between mb-3">
64-
<h2>{title}</h2>
65-
<Button className="btn-primary" type="button">Resume Course</Button>
66-
</div>
67-
<div className="row">
68-
<div className="col col-8">
69-
{sectionIds.map((sectionId) => (
70-
<Section
71-
key={sectionId}
72-
id={sectionId}
73-
courseId={courseId}
74-
/>
75-
))}
76-
</div>
77-
<div className="col col-4">
78-
<CourseDates
79-
start={start}
80-
end={end}
81-
enrollmentStart={enrollmentStart}
82-
enrollmentEnd={enrollmentEnd}
83-
enrollmentMode={enrollmentMode}
84-
isEnrolled={isEnrolled}
85-
/>
86-
</div>
87-
</div>
88-
</div>
59+
<div className="col col-4">
60+
<CourseDates
61+
start={start}
62+
end={end}
63+
enrollmentStart={enrollmentStart}
64+
enrollmentEnd={enrollmentEnd}
65+
enrollmentMode={enrollmentMode}
66+
isEnrolled={isEnrolled}
67+
/>
8968
</div>
90-
</main>
69+
</div>
9170
</>
9271
);
9372
}
94-
95-
CourseHome.propTypes = {
96-
courseId: PropTypes.string.isRequired,
97-
};

src/course-home/CourseHomeContainer.jsx

-54
This file was deleted.

src/course-home/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { default } from './CourseHomeContainer';
1+
export { default } from './CourseHome';

src/course-home/messages.js

-11
This file was deleted.

src/courseware/CoursewareContainer.jsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useSelector, useDispatch } from 'react-redux';
44
import { history } from '@edx/frontend-platform';
55
import { getLocale } from '@edx/frontend-platform/i18n';
66
import { useRouteMatch, Redirect } from 'react-router';
7+
78
import {
89
fetchCourse,
910
fetchSequence,
@@ -14,9 +15,9 @@ import {
1415
saveSequencePosition,
1516
} from './data/thunks';
1617
import { useModel } from '../model-store';
18+
import { TabPage } from '../tab-page';
1719

1820
import Course from './course';
19-
2021
import { sequenceIdsSelector, firstSequenceIdSelector } from './data/selectors';
2122

2223
function useUnitNavigationHandler(courseId, sequenceId, unitId) {
@@ -200,7 +201,10 @@ export default function CoursewareContainer() {
200201
}
201202

202203
return (
203-
<main className="flex-grow-1 d-flex flex-column">
204+
<TabPage
205+
activeTabSlug="courseware"
206+
courseId={courseId}
207+
>
204208
<Course
205209
courseId={courseId}
206210
sequenceId={sequenceId}
@@ -209,7 +213,7 @@ export default function CoursewareContainer() {
209213
previousSequenceHandler={previousSequenceHandler}
210214
unitNavigationHandler={unitNavigationHandler}
211215
/>
212-
</main>
216+
</TabPage>
213217
);
214218
}
215219

0 commit comments

Comments
 (0)