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/page/User.js | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'src/client/react/components/page') diff --git a/src/client/react/components/page/User.js b/src/client/react/components/page/User.js index 0c79a8b..1b7e1ce 100644 --- a/src/client/react/components/page/User.js +++ b/src/client/react/components/page/User.js @@ -1,20 +1,15 @@ import React from 'react'; import PropTypes from 'prop-types'; import { Redirect } from 'react-router-dom'; -import queryString from 'query-string'; -import moment from 'moment'; -import purifyWeek from '../../lib/purifyWeek'; import Search from '../container/Search'; import View from '../container/View'; -import users from '../../users'; +import { userFromMatch } from '../../lib/url'; import WeekSelector from '../container/WeekSelector'; -const UserPage = ({ match, location }) => { - const user = `${match.params.type}/${match.params.value}`; - const weekStr = queryString.parse(location.search).week; - const week = purifyWeek(weekStr ? parseInt(weekStr, 10) : moment().week()); +const UserPage = ({ match }) => { + const user = userFromMatch(match); - if (!users.allIds.includes(user)) { + if (!user) { // Invalid user, redirect to index. return ; } @@ -23,15 +18,15 @@ const UserPage = ({ match, location }) => {
- +
- +
- +
); }; @@ -43,9 +38,6 @@ UserPage.propTypes = { value: PropTypes.string.isRequired, }).isRequired, }).isRequired, - location: PropTypes.shape({ - search: PropTypes.string.isRequired, - }).isRequired, }; export default UserPage; -- cgit v1.1