diff options
author | Noah Loomans <noahloomans@gmail.com> | 2018-02-02 15:52:33 +0100 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2018-02-02 15:52:33 +0100 |
commit | 30376908301dae90d40532210d382c8edc088ac6 (patch) | |
tree | 88c7d228d637f1f5381acf701b75d0fb47b4e7f4 /src/client/react/components/page | |
parent | 614f1c499207a6bebe1457b5b42550c5221286ad (diff) |
Get user and week from context
Diffstat (limited to 'src/client/react/components/page')
-rw-r--r-- | src/client/react/components/page/User.js | 22 |
1 files changed, 7 insertions, 15 deletions
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 <Redirect to="/" />; } @@ -23,15 +18,15 @@ const UserPage = ({ match, location }) => { <div className="page-user"> <div className="search-wrapper"> <div className="search-container"> - <Search urlUser={user} /> + <Search /> </div> </div> <div className="menu"> <div className="menu-container"> - <WeekSelector urlWeek={week} /> + <WeekSelector /> </div> </div> - <View user={user} week={week} /> + <View /> </div> ); }; @@ -43,9 +38,6 @@ UserPage.propTypes = { value: PropTypes.string.isRequired, }).isRequired, }).isRequired, - location: PropTypes.shape({ - search: PropTypes.string.isRequired, - }).isRequired, }; export default UserPage; |