aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/components
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-07-06 18:36:55 +0200
committerNoah Loomans <noahloomans@gmail.com>2018-07-06 18:36:55 +0200
commit74ef968a45e147069d044fbfde814886d7275aa3 (patch)
tree19cbf0296628ba371a289be7619c960e082be15f /src/client/react/components
parent7bfb87a0beda7247f1edc687b34144859813758a (diff)
client/View: Move API call to action
Diffstat (limited to 'src/client/react/components')
-rw-r--r--src/client/react/components/container/View.js51
1 files changed, 11 insertions, 40 deletions
diff --git a/src/client/react/components/container/View.js b/src/client/react/components/container/View.js
index 2ec2dbd..a601226 100644
--- a/src/client/react/components/container/View.js
+++ b/src/client/react/components/container/View.js
@@ -26,6 +26,7 @@ import extractSchedule from '../../lib/extractSchedule';
import Schedule from '../presentational/Schedule';
import Loading from '../presentational/Loading';
+import * as actions from '../../store/actions';
class View extends React.Component {
static propTypes = {
@@ -33,51 +34,15 @@ class View extends React.Component {
state: PropTypes.string.isRequired,
htmlStr: PropTypes.string,
})).isRequired,
-
- // react-router
user: PropTypes.string.isRequired,
week: PropTypes.number.isRequired,
- // redux
- dispatch: PropTypes.func.isRequired,
+ fetchScheduleIfNeeded: PropTypes.func.isRequired,
};
componentDidMount() {
- this.fetchScheduleIfNeeded();
- }
-
- fetchScheduleIfNeeded() {
- const {
- user,
- week,
- schedules,
- dispatch,
- } = this.props;
-
- const schedule = extractSchedule(schedules, user, week);
-
- if (schedule.state === 'NOT_REQUESTED') {
- fetch(`/get/${user}?week=${week}`).then(r => r.text()).then(
- // success
- (htmlStr) => {
- dispatch({
- type: 'VIEW/FETCH_SCHEDULE_SUCCESS',
- user,
- week,
- htmlStr,
- });
- },
-
- // error
- () => {
- dispatch({
- type: 'VIEW/FETCH_SCHEDULE_FAILURE',
- week,
- user,
- });
- },
- );
- }
+ const { fetchScheduleIfNeeded, user, week } = this.props;
+ fetchScheduleIfNeeded(user, week);
}
render() {
@@ -112,4 +77,10 @@ const mapStateToProps = (state) => {
};
};
-export default connect(mapStateToProps)(View);
+const mapDispatchToProps = dispatch => ({
+ fetchScheduleIfNeeded: (user, week) => (
+ dispatch(actions.fetchScheduleIfNeeded(user, week))
+ ),
+});
+
+export default connect(mapStateToProps, mapDispatchToProps)(View);