summaryrefslogtreecommitdiffstats
path: root/webapp/components/new_channel_modal.jsx
diff options
context:
space:
mode:
authorDavid Lu <david.lu@hotmail.com>2016-06-22 10:13:39 -0400
committerChristopher Speller <crspeller@gmail.com>2016-06-22 10:13:39 -0400
commit00dc8e734c5af9e2a7de778b60a2eeaa0e1be269 (patch)
tree8634c6183ffaca6c975eeeae59a2b8940535320a /webapp/components/new_channel_modal.jsx
parent944966f7d1182a055466d874b94470ae840f1f57 (diff)
downloadchat-00dc8e734c5af9e2a7de778b60a2eeaa0e1be269.tar.gz
chat-00dc8e734c5af9e2a7de778b60a2eeaa0e1be269.tar.bz2
chat-00dc8e734c5af9e2a7de778b60a2eeaa0e1be269.zip
PLT-3220 Fixed create channel modal not saving upon enter (#3380)
* fixed create channel modal not saving upon enter * used componentWillReceiveProps
Diffstat (limited to 'webapp/components/new_channel_modal.jsx')
-rw-r--r--webapp/components/new_channel_modal.jsx32
1 files changed, 32 insertions, 0 deletions
diff --git a/webapp/components/new_channel_modal.jsx b/webapp/components/new_channel_modal.jsx
index 45d7169db..9fd76395c 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,23 +26,51 @@ 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({
displayNameError: ''
});
+
+ document.addEventListener('keydown', this.onEnterKeyDown);
+ } else if (nextProps.show === false && this.props.show === true) {
+ document.removeEventListener('keydown', this.onEnterKeyDown);
}
}
+
componentDidMount() {
if (Utils.isBrowserIE()) {
$('body').addClass('browser--ie');
}
+ PreferenceStore.addChangeListener(this.onPreferenceChange);
+ }
+
+ componentWillUnmount() {
+ 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 +82,7 @@ class NewChannelModal extends React.Component {
this.props.onSubmitChannel();
}
+
handleChange() {
const newData = {
displayName: ReactDOM.findDOMNode(this.refs.display_name).value,
@@ -59,6 +90,7 @@ class NewChannelModal extends React.Component {
};
this.props.onDataChanged(newData);
}
+
render() {
var displayNameError = null;
var serverError = null;