aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/components/container
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-01-26 20:30:34 +0100
committerNoah Loomans <noahloomans@gmail.com>2018-01-26 20:30:34 +0100
commit19534b4770b4f4097b02f5fa021a24822b12d907 (patch)
tree4bc0d8ceca5d0c5ae36969dcd14588f0b37f051b /src/client/react/components/container
parent16723546de81e29fa8a31acc4070df5acb182b24 (diff)
Add week selector
Diffstat (limited to 'src/client/react/components/container')
-rw-r--r--src/client/react/components/container/WeekSelector.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/client/react/components/container/WeekSelector.js b/src/client/react/components/container/WeekSelector.js
new file mode 100644
index 0000000..9f308f0
--- /dev/null
+++ b/src/client/react/components/container/WeekSelector.js
@@ -0,0 +1,34 @@
+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';
+
+const WeekSelector = ({ urlWeek, location, history }) => {
+ const updateWeek = (change) => {
+ const newWeek = moment().week(urlWeek.week() + change);
+ const isCurrentWeek = moment().week() === newWeek.week();
+ history.push(`${location.pathname}?${queryString.stringify({ week: isCurrentWeek ? undefined : newWeek.week() })}`);
+ };
+
+ return (
+ <div>
+ <button onClick={() => updateWeek(-1)}>Prev</button>
+ Week {urlWeek.week()}
+ <button onClick={() => updateWeek(+1)}>Next</button>
+ </div>
+ );
+};
+
+WeekSelector.propTypes = {
+ urlWeek: momentPropTypes.momentObj.isRequired,
+ history: PropTypes.shape({
+ push: PropTypes.func.isRequired,
+ }).isRequired,
+ location: PropTypes.shape({
+ pathname: PropTypes.string.isRequired,
+ }).isRequired,
+};
+
+export default withRouter(WeekSelector);