From 30376908301dae90d40532210d382c8edc088ac6 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Fri, 2 Feb 2018 15:52:33 +0100 Subject: Get user and week from context --- src/client/react/components/container/WeekSelector.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/client/react/components/container/WeekSelector.js') diff --git a/src/client/react/components/container/WeekSelector.js b/src/client/react/components/container/WeekSelector.js index d5ba752..a7ffa3a 100644 --- a/src/client/react/components/container/WeekSelector.js +++ b/src/client/react/components/container/WeekSelector.js @@ -8,10 +8,13 @@ import ArrowBackIcon from 'react-icons/lib/md/arrow-back'; import ArrowForwardIcon from 'react-icons/lib/md/arrow-forward'; import purifyWeek from '../../lib/purifyWeek'; +import { weekFromLocation } from '../../lib/url'; + +const WeekSelector = ({ location, history }) => { + const week = weekFromLocation(location); -const WeekSelector = ({ urlWeek, location, history }) => { const updateWeek = (change) => { - const newWeek = purifyWeek(urlWeek + change); + const newWeek = purifyWeek(week + change); const isCurrentWeek = moment().week() === newWeek; const query = queryString.stringify({ @@ -23,19 +26,19 @@ const WeekSelector = ({ urlWeek, location, history }) => { return (
-
Week {urlWeek}
+
Week {week}
); }; WeekSelector.propTypes = { - urlWeek: PropTypes.number.isRequired, - history: PropTypes.shape({ - push: PropTypes.func.isRequired, - }).isRequired, location: PropTypes.shape({ pathname: PropTypes.string.isRequired, + search: PropTypes.string.isRequired, + }).isRequired, + history: PropTypes.shape({ + push: PropTypes.func.isRequired, }).isRequired, }; -- cgit v1.1