From 551b07960ed8ec36c24341f96f2b06fee25ceab3 Mon Sep 17 00:00:00 2001
From: Florian Orben <florian.orben@gmail.com>
Date: Thu, 15 Oct 2015 02:13:48 +0200
Subject: PLT-74: Enable Up Arrow keyboard shortcut to edit your last message

---
 web/react/components/edit_post_modal.jsx | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

(limited to 'web/react/components/edit_post_modal.jsx')

diff --git a/web/react/components/edit_post_modal.jsx b/web/react/components/edit_post_modal.jsx
index 3dbff18cb..38d31d66f 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: ''};
     }
@@ -59,6 +61,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 +82,20 @@ 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();
         });
+
+        PostStore.addEditPostListener(this.handleEditPostEvent);
+    }
+    componentWillUnmount() {
+        PostStore.removeEditPostListener(this.handleEditPostEvent);
     }
     render() {
         var error = (<div className='form-group'><br /></div>);
-- 
cgit v1.2.3-1-g7c22

