ManageCoursePage - edit course
parent
7a147e1dde
commit
1e70e1de6e
|
@ -16,6 +16,8 @@ function ManageCoursePage({ courses, authors, actions, history, ...props }) {
|
|||
actions.loadCourses().catch((error) => {
|
||||
alert("Loading courses failed. " + error);
|
||||
});
|
||||
} else {
|
||||
setCourse({ ...props.course });
|
||||
}
|
||||
|
||||
if (authors.length === 0) {
|
||||
|
@ -23,7 +25,7 @@ function ManageCoursePage({ courses, authors, actions, history, ...props }) {
|
|||
alert("Loading authors failed. " + error);
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
}, [props.course]);
|
||||
|
||||
function handleChange(event) {
|
||||
const { name, value } = event.target;
|
||||
|
@ -59,14 +61,23 @@ ManageCoursePage.propTypes = {
|
|||
history: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
function mapStateToProps(state) {
|
||||
function mapStateToProps(state, ownProps) {
|
||||
const slug = ownProps.match.params.slug;
|
||||
const course =
|
||||
slug && state.courses.length > 0
|
||||
? getCourseBySlug(state.courses, slug)
|
||||
: newCourse;
|
||||
return {
|
||||
course: newCourse,
|
||||
course,
|
||||
courses: state.courses,
|
||||
authors: state.authors
|
||||
};
|
||||
}
|
||||
|
||||
function getCourseBySlug(courses, slug) {
|
||||
return courses.find((course) => course.slug === slug) || null;
|
||||
}
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
actions: bindActionCreators(
|
||||
|
|
Loading…
Reference in New Issue