diff options
author | Noah Loomans <noahloomans@gmail.com> | 2018-01-28 16:06:56 +0100 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2018-01-28 16:06:56 +0100 |
commit | 3b98d4c4f13424c89a10580065075998d37ae857 (patch) | |
tree | 2dc9917bd6c13770aaf07a1e1231cc11d97ec35a /src/client/react/components/container | |
parent | 8670ada517bc8beb69d152c82f282322b9ea8d64 (diff) |
Improve week logic
Diffstat (limited to 'src/client/react/components/container')
-rw-r--r-- | src/client/react/components/container/WeekSelector.js | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/client/react/components/container/WeekSelector.js b/src/client/react/components/container/WeekSelector.js index c9174ca..eef8d8d 100644 --- a/src/client/react/components/container/WeekSelector.js +++ b/src/client/react/components/container/WeekSelector.js @@ -1,17 +1,18 @@ import React from 'react'; import PropTypes from 'prop-types'; import moment from 'moment'; -import momentPropTypes from 'react-moment-proptypes'; import queryString from 'query-string'; import { withRouter } from 'react-router-dom'; +import purifyWeek from '../../lib/purifyWeek'; + const WeekSelector = ({ urlWeek, location, history }) => { const updateWeek = (change) => { - const newWeek = moment().week(urlWeek.week() + change); - const isCurrentWeek = moment().week() === newWeek.week(); + const newWeek = purifyWeek(urlWeek + change); + const isCurrentWeek = moment().week() === newWeek; const query = queryString.stringify({ - week: isCurrentWeek ? undefined : newWeek.week(), + week: isCurrentWeek ? undefined : newWeek, }); history.push(`${location.pathname}?${query}`); }; @@ -19,14 +20,14 @@ const WeekSelector = ({ urlWeek, location, history }) => { return ( <div> <button onClick={() => updateWeek(-1)}>Prev</button> - Week {urlWeek.week()} + Week {urlWeek} <button onClick={() => updateWeek(+1)}>Next</button> </div> ); }; WeekSelector.propTypes = { - urlWeek: momentPropTypes.momentObj.isRequired, + urlWeek: PropTypes.number.isRequired, history: PropTypes.shape({ push: PropTypes.func.isRequired, }).isRequired, |