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
This commit is contained in:
Harrison Healey 2017-11-28 18:31:54 -05:00 committed by enahum
parent 3f6c38d872
commit 33bf655a8c
2 changed files with 29 additions and 14 deletions

View file

@ -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
};

View file

@ -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 = (
<SearchPreview
ref='preview'
focusedPostId={postId}
channelId={focusedChannelId}
focusedPostId={focusedPostId}
navigator={navigator}
onClose={this.handleClosePreview}
onPress={this.handleJumpToChannel}
@ -603,7 +617,7 @@ class Search extends PureComponent {
forceTop={44}
theme={theme}
>
<View style={{flex: 1}}>
<View style={style.container}>
<StatusBar/>
<View style={style.header}>
<SearchBar
@ -652,6 +666,9 @@ class Search extends PureComponent {
const getStyleFromTheme = makeStyleSheetFromTheme((theme) => {
return {
container: {
flex: 1
},
header: {
backgroundColor: theme.sidebarHeaderBg,
width: '100%',