From 33bf655a8cc27e5be72de819edbfa2f7031ba1aa Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Tue, 28 Nov 2017 18:31:54 -0500 Subject: [PATCH] RN-472 Fixed undefined post error in SearchPreview screen (#1217) * RN-472 Fixed undefined post error in SearchPreview screen * Moved SearchPreview container style into StyleSheet --- app/components/search_preview/index.js | 10 ++++---- app/screens/search/search.js | 33 +++++++++++++++++++------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/app/components/search_preview/index.js b/app/components/search_preview/index.js index 8192eed3b..bae5751e1 100644 --- a/app/components/search_preview/index.js +++ b/app/components/search_preview/index.js @@ -4,7 +4,7 @@ import {bindActionCreators} from 'redux'; import {connect} from 'react-redux'; -import {getPost, makeGetPostIdsAroundPost} from 'mattermost-redux/selectors/entities/posts'; +import {makeGetPostIdsAroundPost} from 'mattermost-redux/selectors/entities/posts'; import {getPostsAfter, getPostsBefore, getPostThread} from 'mattermost-redux/actions/posts'; import {makeGetChannel} from 'mattermost-redux/selectors/entities/channels'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; @@ -16,13 +16,11 @@ function makeMapStateToProps() { const getChannel = makeGetChannel(); return function mapStateToProps(state, ownProps) { - const post = getPost(state, ownProps.focusedPostId); - const channel = getChannel(state, {id: post.channel_id}); - const postIds = getPostIdsAroundPost(state, post.id, post.channel_id, {postsBeforeCount: 5, postsAfterCount: 5}); + const channel = getChannel(state, {id: ownProps.channelId}); + const postIds = getPostIdsAroundPost(state, ownProps.focusedPostId, ownProps.channelId, {postsBeforeCount: 5, postsAfterCount: 5}); return { - channelId: post.channel_id, - channelName: channel.display_name, + channelName: channel ? channel.display_name : '', currentUserId: getCurrentUserId(state), postIds }; diff --git a/app/screens/search/search.js b/app/screens/search/search.js index f9d8fb222..70c10c70c 100644 --- a/app/screens/search/search.js +++ b/app/screens/search/search.js @@ -77,7 +77,8 @@ class Search extends PureComponent { this.isX = DeviceInfo.getModel() === 'iPhone X'; this.state = { channelName: '', - postId: null, + focusedChannelId: null, + focusedPostId: null, preview: false, value: '', managedConfig: {} @@ -215,10 +216,13 @@ class Search extends PureComponent { }; previewPost = (post) => { - const focusedPostId = post.id; - Keyboard.dismiss(); - this.setState({preview: true, postId: focusedPostId}); + + this.setState({ + preview: true, + focusedChannelId: post.channel_id, + focusedPostId: post.id + }); }; removeSearchTerms = wrapWithPreventDoubleTap((item) => { @@ -443,7 +447,11 @@ class Search extends PureComponent { }); handleClosePreview = () => { - this.setState({preview: false, postId: null}); + this.setState({ + preview: false, + focusedChannelId: null, + focusedPostId: null + }); }; handleJumpToChannel = (channelId, channelDisplayName) => { @@ -486,7 +494,10 @@ class Search extends PureComponent { theme } = this.props; - const {postId, preview, value} = this.state; + const { + preview, + value + } = this.state; const style = getStyleFromTheme(theme); const sections = [{ data: [{ @@ -578,10 +589,13 @@ class Search extends PureComponent { let previewComponent; if (preview) { + const {focusedChannelId, focusedPostId} = this.state; + previewComponent = ( - + { return { + container: { + flex: 1 + }, header: { backgroundColor: theme.sidebarHeaderBg, width: '100%',