blob: 9f308f0960dbb8d0b64fdd566270b1e0ced3136b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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);
|