From 8018bbc67b10b7b75589b98ed92c6dda1f6163f4 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Thu, 28 Jun 2018 14:33:04 +0200 Subject: Extract shiftWeek from WeekSelector --- src/client/react/components/container/WeekSelector.js | 4 ++-- .../react/components/presentational/WeekSelector.js | 18 ++++-------------- 2 files changed, 6 insertions(+), 16 deletions(-) (limited to 'src/client/react/components') diff --git a/src/client/react/components/container/WeekSelector.js b/src/client/react/components/container/WeekSelector.js index 96c5663..c3f03f1 100644 --- a/src/client/react/components/container/WeekSelector.js +++ b/src/client/react/components/container/WeekSelector.js @@ -20,7 +20,7 @@ import { connect } from 'react-redux'; import { withRouter } from 'react-router-dom'; -import { setWeek } from '../../store/actions'; +import { shiftWeek } from '../../store/actions'; import { weekFromLocation } from '../../lib/url'; import WeekSelector from '../presentational/WeekSelector'; @@ -30,7 +30,7 @@ const mapStateToProps = (state, { location }) => ({ }); const mapDispatchToProps = dispatch => ({ - setWeek: newWeek => dispatch(setWeek(newWeek)), + shiftWeek: newWeek => dispatch(shiftWeek(newWeek)), }); export default withRouter(connect(mapStateToProps, mapDispatchToProps)(WeekSelector)); diff --git a/src/client/react/components/presentational/WeekSelector.js b/src/client/react/components/presentational/WeekSelector.js index e47a175..1b2cfb3 100644 --- a/src/client/react/components/presentational/WeekSelector.js +++ b/src/client/react/components/presentational/WeekSelector.js @@ -25,8 +25,6 @@ import moment from 'moment'; import ArrowBackIcon from 'react-icons/lib/md/arrow-back'; import ArrowForwardIcon from 'react-icons/lib/md/arrow-forward'; -import purifyWeek from '../../lib/purifyWeek'; - import './WeekSelector.scss'; import WeekDisplay from './WeekDisplay'; @@ -34,23 +32,15 @@ class WeekSelector extends React.Component { static propTypes = { // react-router week: PropTypes.number.isRequired, - setWeek: PropTypes.func.isRequired, + shiftWeek: PropTypes.func.isRequired, }; - updateWeek(change) { - const { week, setWeek } = this.props; - const newWeek = purifyWeek(week + change); - - const isCurrentWeek = moment().week() === newWeek; - setWeek(isCurrentWeek ? undefined : newWeek); - } - render() { - const { week } = this.props; + const { week, shiftWeek } = this.props; return (
-
@@ -59,7 +49,7 @@ class WeekSelector extends React.Component { currentWeek={moment().week()} />
-
-- cgit v1.1