Skip to content

Commit

Permalink
MM-19195 - Clear search results before opening RHS for mobile v… (mat…
Browse files Browse the repository at this point in the history
…termost#4031)

* Changed search button in channel header to use new openRHS action that will clear results before opening RHS

* Removed unsed actions

* Removed a couple of more unused actions

* Linting
  • Loading branch information
marianunez committed Oct 24, 2019
1 parent c1a936d commit 172631f
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 13 deletions.
10 changes: 10 additions & 0 deletions actions/views/rhs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {batchActions} from 'redux-batched-actions';

import {SearchTypes} from 'mattermost-redux/action_types';
import {
clearSearch,
getFlaggedPosts,
getPinnedPosts,
searchPostsWithParams,
Expand Down Expand Up @@ -278,3 +279,12 @@ export function selectPost(post) {
export function selectPostCard(post) {
return {type: ActionTypes.SELECT_POST_CARD, postId: post.id, channelId: post.channel_id};
}

export function openRHSSearch() {
return (dispatch) => {
dispatch(clearSearch());
dispatch(updateSearchTerms(''));

dispatch(updateRhsState(RHSStates.SEARCH));
};
}
5 changes: 3 additions & 2 deletions components/channel_header/channel_header.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export default class ChannelHeader extends React.PureComponent {
showFlaggedPosts: PropTypes.func.isRequired,
showPinnedPosts: PropTypes.func.isRequired,
showMentions: PropTypes.func.isRequired,
openRHSSearch: PropTypes.func.isRequired,
closeRightHandSide: PropTypes.func.isRequired,
updateRhsState: PropTypes.func.isRequired,
getCustomEmojisInText: PropTypes.func.isRequired,
updateChannelNotifyProps: PropTypes.func.isRequired,
goToLastViewedChannel: PropTypes.func.isRequired,
Expand Down Expand Up @@ -188,7 +188,8 @@ export default class ChannelHeader extends React.PureComponent {

searchButtonClick = (e) => {
e.preventDefault();
this.props.actions.updateRhsState(RHSStates.SEARCH);

this.props.actions.openRHSSearch();
};

handleShortcut = (e) => {
Expand Down
2 changes: 1 addition & 1 deletion components/channel_header/channel_header.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ describe('components/ChannelHeader', () => {
showFlaggedPosts: jest.fn(),
showPinnedPosts: jest.fn(),
showMentions: jest.fn(),
openRHSSearch: jest.fn(),
closeRightHandSide: jest.fn(),
updateRhsState: jest.fn(),
openModal: jest.fn(),
closeModal: jest.fn(),
getCustomEmojisInText: jest.fn(),
Expand Down
4 changes: 2 additions & 2 deletions components/channel_header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import {
showFlaggedPosts,
showPinnedPosts,
showMentions,
openRHSSearch,
closeRightHandSide,
updateRhsState,
} from 'actions/views/rhs';
import {getRhsState} from 'selectors/rhs';
import {isModalOpen} from 'selectors/views/modals';
Expand Down Expand Up @@ -83,8 +83,8 @@ const mapDispatchToProps = (dispatch) => ({
showFlaggedPosts,
showPinnedPosts,
showMentions,
openRHSSearch,
closeRightHandSide,
updateRhsState,
getCustomEmojisInText,
updateChannelNotifyProps,
goToLastViewedChannel,
Expand Down
4 changes: 2 additions & 2 deletions components/channel_header_mobile/show_search_button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';

import {updateRhsState} from 'actions/views/rhs';
import {openRHSSearch} from 'actions/views/rhs';

import ShowSearchButton from './show_search_button';

const mapDispatchToProps = (dispatch) => ({
actions: bindActionCreators({
updateRhsState,
openRHSSearch,
}, dispatch),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ import React from 'react';
import PropTypes from 'prop-types';

import SearchIcon from 'components/widgets/icons/search_icon';
import {RHSStates} from 'utils/constants';

export default class ShowSearchButton extends React.PureComponent {
static propTypes = {
actions: PropTypes.shape({
updateRhsState: PropTypes.func.isRequired,
openRHSSearch: PropTypes.func.isRequired,
}).isRequired,
}

handleClick = () => {
this.props.actions.updateRhsState(RHSStates.SEARCH);
this.props.actions.openRHSSearch();
}

render() {
Expand Down
6 changes: 3 additions & 3 deletions components/search_results/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import {getCurrentUser} from 'mattermost-redux/selectors/entities/users';
import {getCurrentSearchForCurrentTeam} from 'mattermost-redux/selectors/entities/search';

import {
getSearchResultsTerms,
getSearchTerms,
getIsSearchingTerm,
getIsSearchingFlaggedPost,
getIsSearchingPinnedPost,
getIsSearchGettingMore,
} from 'selectors/rhs';
import {Preferences} from 'utils/constants';
import {Preferences} from 'utils/constants.jsx';

import SearchResults from './search_results.jsx';

Expand Down Expand Up @@ -61,7 +61,7 @@ function makeMapStateToProps() {
results: posts,
matches: getSearchMatches(state),
currentUser: getCurrentUser(state),
searchTerms: getSearchResultsTerms(state),
searchTerms: getSearchTerms(state),
isSearchingTerm: getIsSearchingTerm(state),
isSearchingFlaggedPost: getIsSearchingFlaggedPost(state),
isSearchingPinnedPost: getIsSearchingPinnedPost(state),
Expand Down

0 comments on commit 172631f

Please sign in to comment.