diff --git a/app/components/autocomplete/at_mention/at_mention.js b/app/components/autocomplete/at_mention/at_mention.js index 01dc19b29..93f9a1469 100644 --- a/app/components/autocomplete/at_mention/at_mention.js +++ b/app/components/autocomplete/at_mention/at_mention.js @@ -102,8 +102,8 @@ export default class AtMention extends Component { postDraft: PropTypes.string, requestStatus: PropTypes.string.isRequired, theme: PropTypes.object.isRequired, + onChangeText: PropTypes.func.isRequired, actions: PropTypes.shape({ - changePostDraft: PropTypes.func.isRequired, autocompleteUsersInChannel: PropTypes.func.isRequired }) } @@ -206,7 +206,7 @@ export default class AtMention extends Component { completedDraft += this.props.postDraft.substring(this.props.cursorPosition); } - this.props.actions.changePostDraft(this.props.currentChannelId, completedDraft); + this.props.onChangeText(completedDraft); this.setState({ active: false, mentionComplete: true diff --git a/app/components/autocomplete/at_mention/index.js b/app/components/autocomplete/at_mention/index.js index cab3f86d9..71495cedb 100644 --- a/app/components/autocomplete/at_mention/index.js +++ b/app/components/autocomplete/at_mention/index.js @@ -4,7 +4,6 @@ import {bindActionCreators} from 'redux'; import {connect} from 'react-redux'; -import {handlePostDraftChanged} from 'app/actions/views/channel'; import {autocompleteUsersInChannel} from 'service/actions/users'; import {getTheme} from 'service/selectors/entities/preferences'; import {getDefaultChannel} from 'service/selectors/entities/channels'; @@ -12,10 +11,18 @@ import {getAutocompleteUsersInCurrentChannel} from 'service/selectors/entities/u import AtMention from './at_mention'; -function mapStateToProps(state) { +function mapStateToProps(state, ownProps) { const currentChannelId = state.entities.channels.currentId; - const postDraft = state.views.channel.drafts[currentChannelId]; + + let postDraft; + if (ownProps.rootId.length) { + postDraft = state.views.thread.draft[ownProps.rootId]; + } else { + postDraft = state.views.channel.drafts[currentChannelId]; + } + return { + ...ownProps, currentUserId: state.entities.users.currentId, currentChannelId, currentTeamId: state.entities.teams.currentId, @@ -30,7 +37,6 @@ function mapStateToProps(state) { function mapDispatchToProps(dispatch) { return { actions: bindActionCreators({ - changePostDraft: handlePostDraftChanged, autocompleteUsersInChannel }, dispatch) }; diff --git a/app/components/autocomplete/channel_mention/channel_mention.js b/app/components/autocomplete/channel_mention/channel_mention.js index ee671b508..340c02cce 100644 --- a/app/components/autocomplete/channel_mention/channel_mention.js +++ b/app/components/autocomplete/channel_mention/channel_mention.js @@ -83,8 +83,8 @@ export default class ChannelMention extends Component { postDraft: PropTypes.string, requestStatus: PropTypes.string.isRequired, theme: PropTypes.object.isRequired, + onChangeText: PropTypes.func.isRequired, actions: PropTypes.shape({ - changePostDraft: PropTypes.func.isRequired, autocompleteChannels: PropTypes.func.isRequired }) } @@ -182,7 +182,7 @@ export default class ChannelMention extends Component { completedDraft += this.props.postDraft.substring(this.props.cursorPosition); } - this.props.actions.changePostDraft(this.props.currentChannelId, completedDraft); + this.props.onChangeText(completedDraft); this.setState({ active: false, mentionComplete: true, diff --git a/app/components/autocomplete/channel_mention/index.js b/app/components/autocomplete/channel_mention/index.js index b3714e478..974d49ad7 100644 --- a/app/components/autocomplete/channel_mention/index.js +++ b/app/components/autocomplete/channel_mention/index.js @@ -4,17 +4,24 @@ import {bindActionCreators} from 'redux'; import {connect} from 'react-redux'; -import {handlePostDraftChanged} from 'app/actions/views/channel'; import {autocompleteChannels} from 'service/actions/channels'; import {getTheme} from 'service/selectors/entities/preferences'; import {getAutocompleteChannelWithSections} from 'service/selectors/entities/channels'; import ChannelMention from './channel_mention'; -function mapStateToProps(state) { +function mapStateToProps(state, ownProps) { const currentChannelId = state.entities.channels.currentId; - const postDraft = state.views.channel.drafts[currentChannelId]; + + let postDraft; + if (ownProps.rootId.length) { + postDraft = state.views.thread.draft[ownProps.rootId]; + } else { + postDraft = state.views.channel.drafts[currentChannelId]; + } + return { + ...ownProps, currentChannelId, currentTeamId: state.entities.teams.currentId, postDraft, @@ -27,7 +34,6 @@ function mapStateToProps(state) { function mapDispatchToProps(dispatch) { return { actions: bindActionCreators({ - changePostDraft: handlePostDraftChanged, autocompleteChannels }, dispatch) }; diff --git a/app/components/autocomplete/index.js b/app/components/autocomplete/index.js index d99b4534f..b94dcfcee 100644 --- a/app/components/autocomplete/index.js +++ b/app/components/autocomplete/index.js @@ -1,7 +1,7 @@ // Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import React, {Component} from 'react'; +import React, {PropTypes, Component} from 'react'; import { StyleSheet, View @@ -22,9 +22,14 @@ const style = StyleSheet.create({ }); export default class Autocomplete extends Component { + static propTypes = { + onChangeText: PropTypes.func.isRequired, + rootId: PropTypes.string + }; + state = { cursorPosition: 0 - } + }; handleSelectionChange = (event) => { this.setState({ @@ -36,8 +41,16 @@ export default class Autocomplete extends Component { return ( - - + + ); diff --git a/app/components/post_textbox/post_textbox.js b/app/components/post_textbox/post_textbox.js index 7e1ea0a3c..b175bd309 100644 --- a/app/components/post_textbox/post_textbox.js +++ b/app/components/post_textbox/post_textbox.js @@ -155,7 +155,11 @@ export default class PostTextbox extends PureComponent { {this.renderTyping()} - +