summaryrefslogtreecommitdiffstats
path: root/webapp/components/new_channel_modal.jsx
diff options
context:
space:
mode:
authorDavid Lu <david.lu@hotmail.com>2016-06-20 11:15:27 -0400
committerChristopher Speller <crspeller@gmail.com>2016-06-20 09:15:27 -0600
commitaf02a35b545c1859b14607c1d134bbe54b8b3aaa (patch)
tree4a3cdc65d06c8c3028f9a63e23d7c2c5d6f1d52c /webapp/components/new_channel_modal.jsx
parent1ac3bfa603ef0a5822d7e775c085c3f02fdde359 (diff)
downloadchat-af02a35b545c1859b14607c1d134bbe54b8b3aaa.tar.gz
chat-af02a35b545c1859b14607c1d134bbe54b8b3aaa.tar.bz2
chat-af02a35b545c1859b14607c1d134bbe54b8b3aaa.zip
fixed create channel modal not saving upon enter (#3363)
Diffstat (limited to 'webapp/components/new_channel_modal.jsx')
-rw-r--r--webapp/components/new_channel_modal.jsx30
1 files changed, 30 insertions, 0 deletions
diff --git a/webapp/components/new_channel_modal.jsx b/webapp/components/new_channel_modal.jsx
index 45d7169db..138bee661 100644
--- a/webapp/components/new_channel_modal.jsx
+++ b/webapp/components/new_channel_modal.jsx
@@ -4,6 +4,8 @@
import $ from 'jquery';
import ReactDOM from 'react-dom';
import * as Utils from 'utils/utils.jsx';
+import Constants from 'utils/constants.jsx';
+import PreferenceStore from 'stores/preference_store.jsx';
import {intlShape, injectIntl, defineMessages, FormattedMessage} from 'react-intl';
@@ -24,11 +26,16 @@ class NewChannelModal extends React.Component {
this.handleSubmit = this.handleSubmit.bind(this);
this.handleChange = this.handleChange.bind(this);
+ this.onEnterKeyDown = this.onEnterKeyDown.bind(this);
+ this.onPreferenceChange = this.onPreferenceChange.bind(this);
+
+ this.ctrlSend = PreferenceStore.getBool(Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, 'send_on_ctrl_enter');
this.state = {
displayNameError: ''
};
}
+
componentWillReceiveProps(nextProps) {
if (nextProps.show === true && this.props.show === false) {
this.setState({
@@ -36,11 +43,32 @@ class NewChannelModal extends React.Component {
});
}
}
+
componentDidMount() {
if (Utils.isBrowserIE()) {
$('body').addClass('browser--ie');
}
+ document.addEventListener('keydown', this.onEnterKeyDown);
+ PreferenceStore.addChangeListener(this.onPreferenceChange);
+ }
+
+ componentWillUnmount() {
+ document.removeEventListener('keydown', this.onEnterKeyDown);
+ PreferenceStore.removeChangeListener(this.onPreferenceChange);
+ }
+
+ onPreferenceChange() {
+ this.ctrlSend = PreferenceStore.getBool(Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, 'send_on_ctrl_enter');
}
+
+ onEnterKeyDown(e) {
+ if (this.ctrlSend && e.keyCode === Constants.KeyCodes.ENTER && e.ctrlKey) {
+ this.handleSubmit(e);
+ } else if (!this.ctrlSend && e.keyCode === Constants.KeyCodes.ENTER && !e.shiftKey && !e.altKey) {
+ this.handleSubmit(e);
+ }
+ }
+
handleSubmit(e) {
e.preventDefault();
@@ -52,6 +80,7 @@ class NewChannelModal extends React.Component {
this.props.onSubmitChannel();
}
+
handleChange() {
const newData = {
displayName: ReactDOM.findDOMNode(this.refs.display_name).value,
@@ -59,6 +88,7 @@ class NewChannelModal extends React.Component {
};
this.props.onDataChanged(newData);
}
+
render() {
var displayNameError = null;
var serverError = null;