aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/components/container/WeekSelector.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/react/components/container/WeekSelector.js')
-rw-r--r--src/client/react/components/container/WeekSelector.js13
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,