diff options
author | =Corey Hulen <corey@hulen.com> | 2015-10-16 09:12:30 -0700 |
---|---|---|
committer | =Corey Hulen <corey@hulen.com> | 2015-10-16 09:12:30 -0700 |
commit | 8b2d7f391aedeb5d6bd6490b92bdadf5050e1c73 (patch) | |
tree | 84e426d92eccf017f0fd5ccd22815a2139bd6e44 /web/react/components/edit_post_modal.jsx | |
parent | 6a1755d2e32c3f3bcaa67c33f32cb5eb5ab76ea2 (diff) | |
parent | 9c045f0d4bdf254f57b94356fd2f5f2a2408ed03 (diff) | |
download | chat-8b2d7f391aedeb5d6bd6490b92bdadf5050e1c73.tar.gz chat-8b2d7f391aedeb5d6bd6490b92bdadf5050e1c73.tar.bz2 chat-8b2d7f391aedeb5d6bd6490b92bdadf5050e1c73.zip |
Fixing merge
Diffstat (limited to 'web/react/components/edit_post_modal.jsx')
-rw-r--r-- | web/react/components/edit_post_modal.jsx | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/web/react/components/edit_post_modal.jsx b/web/react/components/edit_post_modal.jsx index 3dbff18cb..90d9696e7 100644 --- a/web/react/components/edit_post_modal.jsx +++ b/web/react/components/edit_post_modal.jsx @@ -5,6 +5,7 @@ var Client = require('../utils/client.jsx'); 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'); export default class EditPostModal extends React.Component { constructor() { @@ -14,6 +15,7 @@ export default class EditPostModal extends React.Component { this.handleEditInput = this.handleEditInput.bind(this); this.handleEditKeyPress = this.handleEditKeyPress.bind(this); this.handleUserInput = this.handleUserInput.bind(this); + this.handleEditPostEvent = this.handleEditPostEvent.bind(this); this.state = {editText: '', title: '', post_id: '', channel_id: '', comments: 0, refocusId: ''}; } @@ -35,16 +37,15 @@ export default class EditPostModal extends React.Component { Client.updatePost(updatedPost, function success() { - AsyncClient.getPosts(this.state.channel_id); + AsyncClient.getPosts(updatedPost.channel_id); window.scrollTo(0, 0); - }.bind(this), + }, function error(err) { AsyncClient.dispatchError(err, 'updatePost'); } ); $('#edit_post').modal('hide'); - $(this.state.refocusId).focus(); } handleEditInput(editMessage) { this.setState({editText: editMessage}); @@ -59,6 +60,18 @@ export default class EditPostModal extends React.Component { handleUserInput(e) { this.setState({editText: e.target.value}); } + handleEditPostEvent(options) { + this.setState({ + editText: options.message || '', + title: options.title || '', + post_id: options.postId || '', + channel_id: options.channelId || '', + comments: options.comments || 0, + refocusId: options.refocusId || '' + }); + + $(React.findDOMNode(this.refs.modal)).modal('show'); + } componentDidMount() { var self = this; @@ -68,12 +81,29 @@ export default class EditPostModal extends React.Component { $(ReactDOM.findDOMNode(this.refs.modal)).on('show.bs.modal', function onShow(e) { var button = e.relatedTarget; + if (!button) { + return; + } self.setState({editText: $(button).attr('data-message'), title: $(button).attr('data-title'), channel_id: $(button).attr('data-channelid'), post_id: $(button).attr('data-postid'), comments: $(button).attr('data-comments'), refocusId: $(button).attr('data-refoucsid')}); }); $(ReactDOM.findDOMNode(this.refs.modal)).on('shown.bs.modal', function onShown() { self.refs.editbox.resize(); + $('#edit_textbox').get(0).focus(); }); + + $(React.findDOMNode(this.refs.modal)).on('hide.bs.modal', function onShown() { + if (self.state.refocusId !== '') { + setTimeout(() => { + $(self.state.refocusId).get(0).focus(); + }); + } + }); + + PostStore.addEditPostListener(this.handleEditPostEvent); + } + componentWillUnmount() { + PostStore.removeEditPostListener(this.handleEditPostEvent); } render() { var error = (<div className='form-group'><br /></div>); |