From 3f0a4ef153d26edfd61276a8aa3c19e16ad522b4 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Sun, 12 Nov 2017 06:34:39 -0500 Subject: [PATCH] RN-472 Improved handling of deleted search results (#1119) --- app/components/post/post.js | 9 ++++- app/screens/search/search.js | 12 ++---- .../search/search_result_post/index.js | 19 +++++++++ .../search_result_post/search_result_post.js | 39 +++++++++++++++++++ 4 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 app/screens/search/search_result_post/index.js create mode 100644 app/screens/search/search_result_post/search_result_post.js diff --git a/app/components/post/post.js b/app/components/post/post.js index f18082dafe..ee296ebe77 100644 --- a/app/components/post/post.js +++ b/app/components/post/post.js @@ -251,11 +251,16 @@ class Post extends PureComponent { }; handlePress = () => { - const {post, onPress} = this.props; + const { + isSearchResult, + onPress, + post + } = this.props; + if (!isToolTipShowing) { if (onPress && post.state !== Posts.POST_DELETED && !isSystemMessage(post) && !isPostPendingOrFailed(post)) { preventDoubleTap(onPress, null, post); - } else if (isPostEphemeral(post)) { + } else if (!isSearchResult && isPostEphemeral(post)) { preventDoubleTap(this.onRemovePost, this, post); } } diff --git a/app/screens/search/search.js b/app/screens/search/search.js index 4a56f3036e..28fe618d2e 100644 --- a/app/screens/search/search.js +++ b/app/screens/search/search.js @@ -22,7 +22,6 @@ import {RequestStatus} from 'mattermost-redux/constants'; import Autocomplete from 'app/components/autocomplete'; import FormattedText from 'app/components/formatted_text'; import Loading from 'app/components/loading'; -import Post from 'app/components/post'; import PostListRetry from 'app/components/post_list_retry'; import SearchBar from 'app/components/search_bar'; import SearchPreview from 'app/components/search_preview'; @@ -31,6 +30,7 @@ import {preventDoubleTap} from 'app/utils/tap'; import {changeOpacity, makeStyleSheetFromTheme} from 'app/utils/theme'; import ChannelDisplayName from './channel_display_name'; +import SearchResultPost from './search_result_post'; const SECTION_HEIGHT = 20; const RECENT_LABEL_HEIGHT = 42; @@ -265,14 +265,10 @@ class Search extends PureComponent { return ( - {separator} diff --git a/app/screens/search/search_result_post/index.js b/app/screens/search/search_result_post/index.js new file mode 100644 index 0000000000..f9d6cbd1c0 --- /dev/null +++ b/app/screens/search/search_result_post/index.js @@ -0,0 +1,19 @@ +// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import {connect} from 'react-redux'; + +import {Posts} from 'mattermost-redux/constants'; +import {getPost} from 'mattermost-redux/selectors/entities/posts'; + +import SearchResultPost from './search_result_post'; + +function mapStateToProps(state, ownProps) { + const post = getPost(state, ownProps.postId); + + return { + isDeleted: post && post.state === Posts.POST_DELETED + }; +} + +export default connect(mapStateToProps)(SearchResultPost); diff --git a/app/screens/search/search_result_post/search_result_post.js b/app/screens/search/search_result_post/search_result_post.js new file mode 100644 index 0000000000..7751c87f59 --- /dev/null +++ b/app/screens/search/search_result_post/search_result_post.js @@ -0,0 +1,39 @@ +// Copyright (c) 201-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import React, {PureComponent} from 'react'; +import PropTypes from 'prop-types'; + +import Post from 'app/components/post'; + +export default class SearchResultPost extends PureComponent { + static propTypes = { + isDeleted: PropTypes.bool.isRequired, + goToThread: PropTypes.func.isRequired, + navigator: PropTypes.object.isRequired, + postId: PropTypes.string.isRequired, + previewPost: PropTypes.func.isRequired + }; + + render() { + const postComponentProps = {}; + + if (this.props.isDeleted) { + postComponentProps.shouldRenderReplyButton = false; + } else { + postComponentProps.onPress = this.props.previewPost; + postComponentProps.onReply = this.props.goToThread; + postComponentProps.shouldRenderReplyButton = true; + } + + return ( + + ); + } +}