Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

MM-19195 - Clear search results before opening RHS for mobile view #4031

Merged
merged 4 commits into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -282,3 +283,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