Skip to content

Commit

Permalink
fix JS errors when Ctrl + Enter is used to send message (mattermost#6708
Browse files Browse the repository at this point in the history
)
  • Loading branch information
saturninoabril authored and hmhealey committed Jun 22, 2017
1 parent cc7484a commit d7b14a0
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions components/edit_channel_header_modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,30 @@ class EditChannelHeaderModal extends React.Component {
super(props);

this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
this.handleSave = this.handleSave.bind(this);
this.handleKeyDown = this.handleKeyDown.bind(this);
this.handleEditKeyPress = this.handleEditKeyPress.bind(this);
this.handleKeyPress = this.handleKeyPress.bind(this);
this.onShow = this.onShow.bind(this);
this.onHide = this.onHide.bind(this);
this.handlePostError = this.handlePostError.bind(this);
this.focusTextbox = this.focusTextbox.bind(this);
this.onPreferenceChange = this.onPreferenceChange.bind(this);

this.ctrlSend = PreferenceStore.getBool(Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, 'send_on_ctrl_enter');

this.state = {
header: props.channel.header,
show: true,
serverError: '',
submitted: false
submitted: false,
ctrlSend: PreferenceStore.getBool(Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, 'send_on_ctrl_enter')
};
}

componentWillMount() {
this.setState({
ctrlSend: PreferenceStore.getBool(Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, 'send_on_ctrl_enter')
});
}

componentDidMount() {
PreferenceStore.addChangeListener(this.onPreferenceChange);
this.onShow();
Expand All @@ -68,10 +73,12 @@ class EditChannelHeaderModal extends React.Component {
}

onPreferenceChange() {
this.ctrlSend = PreferenceStore.getBool(Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, 'send_on_ctrl_enter');
this.setState({
ctrlSend: PreferenceStore.getBool(Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, 'send_on_ctrl_enter')
});
}

handleSubmit() {
handleSave() {
this.setState({submitted: true});

updateChannelHeader(
Expand Down Expand Up @@ -101,29 +108,23 @@ class EditChannelHeaderModal extends React.Component {

focusTextbox() {
if (!Utils.isMobile()) {
this.refs.textbox.focus();
this.refs.editChannelHeaderTextbox.focus();
}
}

handleKeyDown(e) {
if (this.ctrlSend && e.keyCode === Constants.KeyCodes.ENTER && e.ctrlKey) {
e.preventDefault();
this.handleSubmit(e);
} else if (!this.ctrlSend && e.keyCode === Constants.KeyCodes.ENTER && !e.shiftKey && !e.altKey) {
e.preventDefault();
this.handleSubmit(e);
if (this.state.ctrlSend && e.keyCode === KeyCodes.ENTER && e.ctrlKey === true) {
this.handleKeyPress(e);
}
}

handleEditKeyPress(e) {
if (!UserAgent.isMobile() && !this.state.ctrlSend && e.which === KeyCodes.ENTER && !e.shiftKey && !e.altKey) {
e.preventDefault();
ReactDOM.findDOMNode(this.refs.editbox).blur();
this.handleEdit();
} else if (this.state.ctrlSend && e.ctrlKey && e.which === KeyCodes.ENTER) {
e.preventDefault();
ReactDOM.findDOMNode(this.refs.editbox).blur();
this.handleEdit();
handleKeyPress(e) {
if (!UserAgent.isMobile() && ((this.state.ctrlSend && e.ctrlKey) || !this.state.ctrlSend)) {
if (e.which === KeyCodes.ENTER && !e.shiftKey && !e.altKey) {
e.preventDefault();
ReactDOM.findDOMNode(this.refs.editChannelHeaderTextbox).blur();
this.handleSave(e);
}
}
}

Expand Down Expand Up @@ -179,15 +180,15 @@ class EditChannelHeaderModal extends React.Component {
<Textbox
value={this.state.header}
onChange={this.handleChange}
onKeyPress={this.handleEditKeyPress}
onKeyPress={this.handleKeyPress}
onKeyDown={this.handleKeyDown}
supportsCommands={false}
suggestionListStyle='bottom'
createMessage={Utils.localizeMessage('edit_channel_header.editHeader', 'Edit the Channel Header...')}
previewMessageLink={Utils.localizeMessage('edit_channel_header.previewHeader', 'Edit Header')}
handlePostError={this.handlePostError}
id='edit_textbox'
ref='textbox'
ref='editChannelHeaderTextbox'
/>
<br/>
{serverError}
Expand All @@ -208,7 +209,7 @@ class EditChannelHeaderModal extends React.Component {
disabled={this.state.submitted}
type='button'
className='btn btn-primary'
onClick={this.handleSubmit}
onClick={this.handleSave}
>
<FormattedMessage
id='edit_channel_header_modal.save'
Expand Down

0 comments on commit d7b14a0

Please sign in to comment.