Commit 3a225804 authored by Joram Wilander's avatar Joram Wilander Committed by JoramWilander
Browse files

Fix channel switcher button and shortcut (#2099)

parent cf25d222
......@@ -53,6 +53,7 @@ export default class ChannelHeader extends React.PureComponent {
rhsState: PropTypes.oneOf(
Object.values(RHSStates),
),
isQuickSwitcherOpen: PropTypes.bool,
actions: PropTypes.shape({
favoriteChannel: PropTypes.func.isRequired,
unfavoriteChannel: PropTypes.func.isRequired,
......@@ -79,7 +80,6 @@ export default class ChannelHeader extends React.PureComponent {
const showSearchBar = Utils.windowWidth() > SEARCH_BAR_MINIMUM_WINDOW_SIZE;
this.state = {
showSearchBar,
showQuickSwitch: false,
};
this.getHeaderMarkdownOptions = memoizeResult((channelNamesMap) => (
......@@ -214,17 +214,15 @@ export default class ChannelHeader extends React.PureComponent {
}
toggleQuickSwitchModal = () => {
const {showQuickSwitch} = this.state;
if (showQuickSwitch) {
const {isQuickSwitcherOpen} = this.props;
if (isQuickSwitcherOpen) {
this.props.actions.closeModal(ModalIdentifiers.QUICK_SWITCH);
} else {
this.props.actions.openModal({
modalId: ModalIdentifiers.QUICK_SWITCH,
dialogType: QuickSwitchModal,
});
} else {
this.props.actions.closeModal(ModalIdentifiers.QUICK_SWITCH);
}
this.setState({showQuickSwitch: !showQuickSwitch});
}
render() {
......
......@@ -35,6 +35,8 @@ import {
updateRhsState,
} from 'actions/views/rhs';
import {getRhsState} from 'selectors/rhs';
import {isModalOpen} from 'selectors/views/modals';
import {ModalIdentifiers} from 'utils/constants';
import ChannelHeader from './channel_header';
......@@ -58,6 +60,7 @@ const mapStateToProps = (state) => {
isFavorite: isCurrentChannelFavorite(state),
isReadOnly: isCurrentChannelReadOnly(state),
isMuted: isCurrentChannelMuted(state),
isQuickSwitcherOpen: isModalOpen(state, ModalIdentifiers.QUICK_SWITCH),
};
};
......
......@@ -20,6 +20,7 @@ import {haveITeamPermission} from 'mattermost-redux/selectors/entities/roles';
import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams';
import {switchToChannelById} from 'actions/views/channel';
import {openModal} from 'actions/views/modals';
import {close} from 'actions/views/lhs';
import {getIsLhsOpen} from 'selectors/lhs';
......@@ -74,6 +75,7 @@ function mapDispatchToProps(dispatch) {
actions: bindActionCreators({
close,
switchToChannelById,
openModal,
}, dispatch),
};
}
......
......@@ -13,15 +13,15 @@ import {SpringSystem, MathUtil} from 'rebound';
import {browserHistory} from 'utils/browser_history';
import {trackEvent} from 'actions/diagnostics_actions.jsx';
import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
import * as ChannelUtils from 'utils/channel_utils.jsx';
import {ActionTypes, Constants} from 'utils/constants.jsx';
import {Constants, ModalIdentifiers} from 'utils/constants.jsx';
import * as Utils from 'utils/utils.jsx';
import {t} from 'utils/i18n';
import favicon from 'images/favicon/favicon-16x16.png';
import redFavicon from 'images/favicon/redfavicon-16x16.png';
import MoreChannels from 'components/more_channels';
import MoreDirectChannels from 'components/more_direct_channels';
import QuickSwitchModal from 'components/quick_switch_modal';
import NewChannelFlow from 'components/new_channel_flow';
import UnreadChannelIndicator from 'components/unread_channel_indicator.jsx';
import Pluggable from 'plugins/pluggable';
......@@ -136,6 +136,7 @@ export default class Sidebar extends React.PureComponent {
actions: PropTypes.shape({
close: PropTypes.func.isRequired,
switchToChannelById: PropTypes.func.isRequired,
openModal: PropTypes.func.isRequired,
}).isRequired,
};
......@@ -512,8 +513,9 @@ export default class Sidebar extends React.PureComponent {
openQuickSwitcher = (e) => {
e.preventDefault();
AppDispatcher.handleViewAction({
type: ActionTypes.TOGGLE_QUICK_SWITCH_MODAL,
this.props.actions.openModal({
modalId: ModalIdentifiers.QUICK_SWITCH,
dialogType: QuickSwitchModal,
});
}
......
......@@ -134,6 +134,7 @@ describe('component/sidebar/sidebar_channel/SidebarChannel', () => {
actions: {
close: jest.fn(),
switchToChannelById: jest.fn(),
openModal: jest.fn(),
},
canCreatePublicChannel: true,
canCreatePrivateChannel: true,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment