aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/components/container
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/react/components/container')
-rw-r--r--src/client/react/components/container/RoomFinder.js9
-rw-r--r--src/client/react/components/container/Search.js9
-rw-r--r--src/client/react/components/container/View.js39
-rw-r--r--src/client/react/components/container/WeekSelector.js6
4 files changed, 29 insertions, 34 deletions
diff --git a/src/client/react/components/container/RoomFinder.js b/src/client/react/components/container/RoomFinder.js
index b4af8cb..e502250 100644
--- a/src/client/react/components/container/RoomFinder.js
+++ b/src/client/react/components/container/RoomFinder.js
@@ -19,14 +19,13 @@
*/
import { connect } from 'react-redux';
-import { withRouter } from 'react-router-dom';
import { shiftRoom } from '../../store/actions';
-import { userFromMatch } from '../../lib/url';
+import { selectUser } from '../../store/selectors';
import RoomFinder from '../presentational/RoomFinder';
-const mapStateToProps = (state, { match }) => {
- const user = userFromMatch(match);
+const mapStateToProps = (state) => {
+ const user = selectUser(state);
return {
key: user,
@@ -40,4 +39,4 @@ const mapDispatchToProps = dispatch => ({
onHide: () => dispatch({ type: 'ROOM_FINDER/HIDE' }),
});
-export default withRouter(connect(mapStateToProps, mapDispatchToProps)(RoomFinder));
+export default connect(mapStateToProps, mapDispatchToProps)(RoomFinder);
diff --git a/src/client/react/components/container/Search.js b/src/client/react/components/container/Search.js
index 73919d3..ca2e372 100644
--- a/src/client/react/components/container/Search.js
+++ b/src/client/react/components/container/Search.js
@@ -20,14 +20,13 @@
import { connect } from 'react-redux';
-import { withRouter } from 'react-router-dom';
import Search from '../presentational/Search';
import { setUser as setUserAction } from '../../store/actions';
-import { userFromLocation } from '../../lib/url';
import users from '../../users';
+import { selectUser } from '../../store/selectors';
-const mapStateToProps = (state, { location }) => {
- const currentUser = userFromLocation(location);
+const mapStateToProps = (state) => {
+ const currentUser = selectUser(state);
const selectedUser = state.search && state.search.selected;
let searchText;
let isExactMatch;
@@ -63,4 +62,4 @@ const mapDispatchToProps = dispatch => ({
}),
});
-export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Search));
+export default connect(mapStateToProps, mapDispatchToProps)(Search);
diff --git a/src/client/react/components/container/View.js b/src/client/react/components/container/View.js
index 407a7de..2ec2dbd 100644
--- a/src/client/react/components/container/View.js
+++ b/src/client/react/components/container/View.js
@@ -21,9 +21,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
-import { withRouter } from 'react-router-dom';
-
-import { userFromMatch, weekFromLocation } from '../../lib/url';
+import { selectUser, selectWeek } from '../../store/selectors';
import extractSchedule from '../../lib/extractSchedule';
import Schedule from '../presentational/Schedule';
@@ -37,8 +35,8 @@ class View extends React.Component {
})).isRequired,
// react-router
- match: PropTypes.object.isRequired,
- location: PropTypes.object.isRequired,
+ user: PropTypes.string.isRequired,
+ week: PropTypes.number.isRequired,
// redux
dispatch: PropTypes.func.isRequired,
@@ -48,20 +46,14 @@ class View extends React.Component {
this.fetchScheduleIfNeeded();
}
- componentDidUpdate() {
- this.fetchScheduleIfNeeded();
- }
-
fetchScheduleIfNeeded() {
const {
+ user,
+ week,
schedules,
- match,
- location,
dispatch,
} = this.props;
- const user = userFromMatch(match);
- const week = weekFromLocation(location);
const schedule = extractSchedule(schedules, user, week);
if (schedule.state === 'NOT_REQUESTED') {
@@ -90,13 +82,11 @@ class View extends React.Component {
render() {
const {
+ user,
+ week,
schedules,
- match,
- location,
} = this.props;
- const user = userFromMatch(match);
- const week = weekFromLocation(location);
const schedule = extractSchedule(schedules, user, week);
switch (schedule.state) {
@@ -111,8 +101,15 @@ class View extends React.Component {
}
}
-const mapStateToProps = state => ({
- schedules: state.schedules,
-});
+const mapStateToProps = (state) => {
+ const user = selectUser(state);
+ const week = selectWeek(state);
+ return {
+ key: `${user}:${week}`,
+ user,
+ week,
+ schedules: state.schedules,
+ };
+};
-export default withRouter(connect(mapStateToProps)(View));
+export default connect(mapStateToProps)(View);
diff --git a/src/client/react/components/container/WeekSelector.js b/src/client/react/components/container/WeekSelector.js
index c3f03f1..eeba0e7 100644
--- a/src/client/react/components/container/WeekSelector.js
+++ b/src/client/react/components/container/WeekSelector.js
@@ -21,12 +21,12 @@
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import { shiftWeek } from '../../store/actions';
-import { weekFromLocation } from '../../lib/url';
+import { selectWeek } from '../../store/selectors';
import WeekSelector from '../presentational/WeekSelector';
-const mapStateToProps = (state, { location }) => ({
- week: weekFromLocation(location),
+const mapStateToProps = state => ({
+ week: selectWeek(state),
});
const mapDispatchToProps = dispatch => ({