60 lines
1.3 KiB
JavaScript
60 lines
1.3 KiB
JavaScript
import React from "react";
|
|
import { connect } from "react-redux";
|
|
import { loadCourses } from "../../redux/actions/courseActions";
|
|
import { loadAuthors } from "../../redux/actions/authorActions";
|
|
import PropTypes from "prop-types";
|
|
import { bindActionCreators } from "redux";
|
|
|
|
class ManageCoursePage extends React.Component {
|
|
componentDidMount() {
|
|
const { courses, authors, actions } = this.props;
|
|
|
|
if (courses.length === 0) {
|
|
actions.loadCourses().catch((error) => {
|
|
alert("Loading courses failed. " + error);
|
|
});
|
|
}
|
|
|
|
if (authors.length === 0) {
|
|
actions.loadAuthors().catch((error) => {
|
|
alert("Loading authors failed. " + error);
|
|
});
|
|
}
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<>
|
|
<h2>Manage course</h2>
|
|
</>
|
|
);
|
|
}
|
|
}
|
|
|
|
ManageCoursePage.propTypes = {
|
|
courses: PropTypes.array.isRequired,
|
|
authors: PropTypes.array.isRequired,
|
|
actions: PropTypes.object.isRequired
|
|
};
|
|
|
|
function mapStateToProps(state) {
|
|
return {
|
|
courses: state.courses,
|
|
authors: state.authors
|
|
};
|
|
}
|
|
|
|
function mapDispatchToProps(dispatch) {
|
|
return {
|
|
actions: bindActionCreators(
|
|
{
|
|
loadCourses,
|
|
loadAuthors
|
|
},
|
|
dispatch
|
|
)
|
|
};
|
|
}
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(ManageCoursePage);
|