From 5119e96366060cceea8111bda26c237eb7a6758f Mon Sep 17 00:00:00 2001 From: Florian Orben Date: Thu, 29 Oct 2015 00:35:54 +0100 Subject: enable ctrl+enter send for edit msg modal --- web/react/components/edit_post_modal.jsx | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/web/react/components/edit_post_modal.jsx b/web/react/components/edit_post_modal.jsx index e5bede026..d8d7bc423 100644 --- a/web/react/components/edit_post_modal.jsx +++ b/web/react/components/edit_post_modal.jsx @@ -6,6 +6,10 @@ var AsyncClient = require('../utils/async_client.jsx'); var Textbox = require('./textbox.jsx'); var BrowserStore = require('../stores/browser_store.jsx'); var PostStore = require('../stores/post_store.jsx'); +var PreferenceStore = require('../stores/preference_store.jsx'); + +var Constants = require('../utils/constants.jsx'); +var KeyCodes = Constants.KeyCodes; export default class EditPostModal extends React.Component { constructor() { @@ -16,6 +20,8 @@ export default class EditPostModal extends React.Component { this.handleEditKeyPress = this.handleEditKeyPress.bind(this); this.handleUserInput = this.handleUserInput.bind(this); this.handleEditPostEvent = this.handleEditPostEvent.bind(this); + this.handleKeyDown = this.handleKeyDown.bind(this); + this.onPreferenceChange = this.onPreferenceChange.bind(this); this.state = {editText: '', title: '', post_id: '', channel_id: '', comments: 0, refocusId: ''}; } @@ -51,10 +57,12 @@ export default class EditPostModal extends React.Component { this.setState({editText: editMessage}); } handleEditKeyPress(e) { - if (e.which === 13 && !e.shiftKey && !e.altKey) { - e.preventDefault(); - ReactDOM.findDOMNode(this.refs.editbox).blur(); - this.handleEdit(e); + if (this.state.ctrlSend === 'true' && e.ctrlKey || this.state.ctrlSend === 'false') { + if (e.which === KeyCodes.ENTER && !e.shiftKey && !e.altKey) { + e.preventDefault(); + ReactDOM.findDOMNode(this.refs.editbox).blur(); + this.handleEdit(e); + } } } handleUserInput(e) { @@ -72,6 +80,16 @@ export default class EditPostModal extends React.Component { $(ReactDOM.findDOMNode(this.refs.modal)).modal('show'); } + handleKeyDown(e) { + if (this.state.ctrlSend === 'true' && e.keyCode === KeyCodes.ENTER && e.ctrlKey === true) { + this.handleEdit(e); + } + } + onPreferenceChange() { + this.setState({ + ctrlSend: PreferenceStore.getPreference(Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, 'send_on_ctrl_enter', {value: 'false'}).value + }); + } componentDidMount() { var self = this; @@ -101,9 +119,11 @@ export default class EditPostModal extends React.Component { }); PostStore.addEditPostListener(this.handleEditPostEvent); + PreferenceStore.addChangeListener(this.onPreferenceChange); } componentWillUnmount() { PostStore.removeEditPostListener(this.handleEditPostEvent); + PreferenceStore.removeEditPostListener(this.onPreferenceChange); } render() { var error = (

); @@ -138,6 +158,7 @@ export default class EditPostModal extends React.Component { Date: Thu, 29 Oct 2015 17:31:47 +0100 Subject: fix component unmount --- web/react/components/edit_post_modal.jsx | 2 +- web/react/components/post_attachment.jsx | 69 ++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 web/react/components/post_attachment.jsx diff --git a/web/react/components/edit_post_modal.jsx b/web/react/components/edit_post_modal.jsx index d8d7bc423..2629d6b25 100644 --- a/web/react/components/edit_post_modal.jsx +++ b/web/react/components/edit_post_modal.jsx @@ -123,7 +123,7 @@ export default class EditPostModal extends React.Component { } componentWillUnmount() { PostStore.removeEditPostListener(this.handleEditPostEvent); - PreferenceStore.removeEditPostListener(this.onPreferenceChange); + PreferenceStore.removeChangeListener(this.onPreferenceChange); } render() { var error = (

); diff --git a/web/react/components/post_attachment.jsx b/web/react/components/post_attachment.jsx new file mode 100644 index 000000000..d92637749 --- /dev/null +++ b/web/react/components/post_attachment.jsx @@ -0,0 +1,69 @@ +export default class PostAttachment extends React.Component { + constructor(props) { + super(props); + } + + render() { + return ( +
+ {'Pre text'} +
+
+ + + {'@testuser'} + +

+ + {'Attachment title'} + +

+
+
+

+ {'This is the main text in a message attachment, and can contain standard message markup (see details below).'} +

+ + + + + + + + + + + + + + +
{'Assigned to'}{'Priority'}
{'Paul'}{'Critical'}
+
+
+ +
+
+
+
+
+
+ ); + } +} \ No newline at end of file -- cgit v1.2.3-1-g7c22 From 7e70788c947af34e742b681aab2ecdcde63b7463 Mon Sep 17 00:00:00 2001 From: Florian Orben Date: Thu, 29 Oct 2015 17:39:22 +0100 Subject: simplify check if ctrl+enter was pressed --- web/react/components/edit_post_modal.jsx | 10 ++--- web/react/components/post_attachment.jsx | 69 -------------------------------- 2 files changed, 4 insertions(+), 75 deletions(-) delete mode 100644 web/react/components/post_attachment.jsx diff --git a/web/react/components/edit_post_modal.jsx b/web/react/components/edit_post_modal.jsx index 2629d6b25..2abb3f151 100644 --- a/web/react/components/edit_post_modal.jsx +++ b/web/react/components/edit_post_modal.jsx @@ -57,12 +57,10 @@ export default class EditPostModal extends React.Component { this.setState({editText: editMessage}); } handleEditKeyPress(e) { - if (this.state.ctrlSend === 'true' && e.ctrlKey || this.state.ctrlSend === 'false') { - if (e.which === KeyCodes.ENTER && !e.shiftKey && !e.altKey) { - e.preventDefault(); - ReactDOM.findDOMNode(this.refs.editbox).blur(); - this.handleEdit(e); - } + if (this.state.ctrlSend === 'false' && e.which === KeyCodes.ENTER && !e.shiftKey && !e.altKey) { + e.preventDefault(); + ReactDOM.findDOMNode(this.refs.editbox).blur(); + this.handleEdit(e); } } handleUserInput(e) { diff --git a/web/react/components/post_attachment.jsx b/web/react/components/post_attachment.jsx deleted file mode 100644 index d92637749..000000000 --- a/web/react/components/post_attachment.jsx +++ /dev/null @@ -1,69 +0,0 @@ -export default class PostAttachment extends React.Component { - constructor(props) { - super(props); - } - - render() { - return ( -
- {'Pre text'} -
-
- - - {'@testuser'} - -

- - {'Attachment title'} - -

-
-
-

- {'This is the main text in a message attachment, and can contain standard message markup (see details below).'} -

- - - - - - - - - - - - - - -
{'Assigned to'}{'Priority'}
{'Paul'}{'Critical'}
-
-
- -
-
-
-
-
-
- ); - } -} \ No newline at end of file -- cgit v1.2.3-1-g7c22