diff options
author | David Lu <david.lu@hotmail.com> | 2016-06-04 23:23:07 -0700 |
---|---|---|
committer | enahum <nahumhbl@gmail.com> | 2016-06-05 03:23:07 -0300 |
commit | cc4d23e27669ce85285b514a0606b4ea8c27d6e7 (patch) | |
tree | af28627ab19dfcb1044f4d8e486459d9d94b6f0a /webapp/components/edit_channel_header_modal.jsx | |
parent | cb868eb42bdd6a5a30fe111faa48875a4c13f09c (diff) | |
download | chat-cc4d23e27669ce85285b514a0606b4ea8c27d6e7.tar.gz chat-cc4d23e27669ce85285b514a0606b4ea8c27d6e7.tar.bz2 chat-cc4d23e27669ce85285b514a0606b4ea8c27d6e7.zip |
added ctrlSend checking (#3196)
Diffstat (limited to 'webapp/components/edit_channel_header_modal.jsx')
-rw-r--r-- | webapp/components/edit_channel_header_modal.jsx | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/webapp/components/edit_channel_header_modal.jsx b/webapp/components/edit_channel_header_modal.jsx index 6a7cccebb..ea411357d 100644 --- a/webapp/components/edit_channel_header_modal.jsx +++ b/webapp/components/edit_channel_header_modal.jsx @@ -6,6 +6,7 @@ import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; import Client from 'utils/web_client.jsx'; import Constants from 'utils/constants.jsx'; import * as Utils from 'utils/utils.jsx'; +import PreferenceStore from 'stores/preference_store.jsx'; import {intlShape, injectIntl, defineMessages, FormattedMessage} from 'react-intl'; @@ -26,9 +27,12 @@ class EditChannelHeaderModal extends React.Component { this.handleChange = this.handleChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); - + this.handleKeyDown = this.handleKeyDown.bind(this); this.onShow = this.onShow.bind(this); this.onHide = this.onHide.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, @@ -40,10 +44,16 @@ class EditChannelHeaderModal extends React.Component { if (this.props.show) { this.onShow(); } + + PreferenceStore.addChangeListener(this.onPreferenceChange); + } + + componentWillUnmount() { + PreferenceStore.removeChangeListener(this.onPreferenceChange); } componentWillReceiveProps(nextProps) { - if (this.props.channel.header !== nextProps.channel.header) { + if (this.props !== nextProps) { this.setState({ header: nextProps.channel.header }); @@ -62,6 +72,10 @@ class EditChannelHeaderModal extends React.Component { }); } + onPreferenceChange() { + this.ctrlSend = PreferenceStore.getBool(Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, 'send_on_ctrl_enter'); + } + handleSubmit() { Client.updateChannelHeader( this.props.channel.id, @@ -99,6 +113,16 @@ class EditChannelHeaderModal extends React.Component { this.props.onHide(); } + 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); + } + } + render() { var serverError = null; if (this.state.serverError) { @@ -136,6 +160,7 @@ class EditChannelHeaderModal extends React.Component { maxLength='1024' value={this.state.header} onChange={this.handleChange} + onKeyDown={this.handleKeyDown} /> {serverError} </Modal.Body> |