diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/react/components/container/Menu.js | 21 | ||||
-rw-r--r-- | src/client/react/components/container/RoomFinder.js | 16 |
2 files changed, 24 insertions, 13 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)); diff --git a/src/client/react/components/container/RoomFinder.js b/src/client/react/components/container/RoomFinder.js index 5f25fd7..97ed175 100644 --- a/src/client/react/components/container/RoomFinder.js +++ b/src/client/react/components/container/RoomFinder.js @@ -26,7 +26,7 @@ import { Button, ButtonIcon } from 'rmwc/Button'; import users from '../../users'; import { setUser, userFromMatch } from '../../lib/url'; -class HelpBox extends React.Component { +class RoomFinder extends React.Component { static propTypes = { // redux isVisible: PropTypes.bool.isRequired, @@ -46,23 +46,17 @@ class HelpBox extends React.Component { componentWillMount() { const user = userFromMatch(this.props.match); - // Have we just been mounted and are we viewing something else then a room? if (this.props.isVisible && users.byId[user].type !== 'r') { + // We are not currently viewing a room, so just hide. this.props.dispatch({ type: 'ROOM_FINDER/HIDE' }); } } componentWillReceiveProps(nextProps) { const user = userFromMatch(nextProps.match); - // We are not currently viewing a room, correct the situation. if (nextProps.isVisible && users.byId[user].type !== 'r') { - // Did we just become visible? Set the user to a room. If not, hide. - if (!this.props.isVisible) { - // Set the room to the first room. - setUser(users.allRoomIds[0], nextProps.location, nextProps.history); - } else { - this.props.dispatch({ type: 'ROOM_FINDER/HIDE' }); - } + // We are not currently viewing a room, so just hide. + this.props.dispatch({ type: 'ROOM_FINDER/HIDE' }); } } @@ -106,4 +100,4 @@ const mapStateToProps = state => ({ isVisible: state.isRoomFinderVisible, }); -export default withRouter(connect(mapStateToProps)(HelpBox)); +export default withRouter(connect(mapStateToProps)(RoomFinder)); |