aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/components/container/Menu.js
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-03-20 16:24:38 +0100
committerNoah Loomans <noahloomans@gmail.com>2018-03-20 16:25:30 +0100
commit6be2de249c494370283bb2a23a48500ed6e2871b (patch)
treec5deac45d311aa780f9bba8dde95eb54ce82ad22 /src/client/react/components/container/Menu.js
parent9470394383bb0105053937a149472189940016df (diff)
Move switching setting user to a room code to Menu
This ensures tapping the room finder button always works, even when no room is selected in the first place.
Diffstat (limited to 'src/client/react/components/container/Menu.js')
-rw-r--r--src/client/react/components/container/Menu.js21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/client/react/components/container/Menu.js b/src/client/react/components/container/Menu.js
index f99ed37..920973b 100644
--- a/src/client/react/components/container/Menu.js
+++ b/src/client/react/components/container/Menu.js
@@ -20,21 +20,38 @@
import React from 'react';
import { connect } from 'react-redux';
+import { withRouter } from 'react-router-dom';
import { PropTypes } from 'prop-types';
import { Button, ButtonIcon } from 'rmwc/Button';
import { SimpleMenu, MenuItem } from 'rmwc/Menu';
import { Icon } from 'rmwc/Icon';
+import users from '../../users';
+import { setUser, userFromMatch } from '../../lib/url';
class Menu extends React.Component {
static propTypes = {
+ // redux
dispatch: PropTypes.func.isRequired,
+
+ // react-router
+ match: PropTypes.object.isRequired,
+ location: PropTypes.object.isRequired,
+ history: PropTypes.object.isRequired,
}
onItemSelected(index) {
switch (index) {
- case 'room_finder':
+ case 'room_finder': {
+ const user = userFromMatch(this.props.match);
+
+ if (user == null || users.byId[user].type !== 'r') {
+ // We are not currently viewing a room, correct the situation.
+ setUser(users.allRoomIds[0], this.props.location, this.props.history);
+ }
+
this.props.dispatch({ type: 'ROOM_FINDER/SHOW' });
break;
+ }
default:
// No default
}
@@ -59,4 +76,4 @@ class Menu extends React.Component {
}
}
-export default connect()(Menu);
+export default withRouter(connect()(Menu));