diff options
author | Noah Loomans <noahloomans@gmail.com> | 2018-06-28 14:33:04 +0200 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2018-06-28 14:33:04 +0200 |
commit | 8018bbc67b10b7b75589b98ed92c6dda1f6163f4 (patch) | |
tree | 2f6ebd53ee3d8f32fad34de0191d911ddc65757e /src/client/react/components | |
parent | e61429154d4c06e0362abd55482400a45b7636ab (diff) |
Extract shiftWeek from WeekSelector
Diffstat (limited to 'src/client/react/components')
-rw-r--r-- | src/client/react/components/container/WeekSelector.js | 4 | ||||
-rw-r--r-- | src/client/react/components/presentational/WeekSelector.js | 18 |
2 files changed, 6 insertions, 16 deletions
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 ( <div className="WeekSelector"> - <button type="button" onClick={() => this.updateWeek(-1)}> + <button type="button" onClick={() => shiftWeek(-1)}> <ArrowBackIcon /> </button> <div className="text"> @@ -59,7 +49,7 @@ class WeekSelector extends React.Component { currentWeek={moment().week()} /> </div> - <button type="button" onClick={() => this.updateWeek(+1)}> + <button type="button" onClick={() => shiftWeek(+1)}> <ArrowForwardIcon /> </button> </div> |