From 6a056a0042d0df6c1c377d4bfeb6a3d10017ae3f Mon Sep 17 00:00:00 2001
From: Joram Wilander <jwawilander@gmail.com>
Date: Wed, 12 Jul 2017 09:49:03 -0400
Subject: Fix posting when allow edit after time set (#6913)

---
 webapp/components/dot_menu/dot_menu.jsx | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

(limited to 'webapp/components/dot_menu/dot_menu.jsx')

diff --git a/webapp/components/dot_menu/dot_menu.jsx b/webapp/components/dot_menu/dot_menu.jsx
index eb6a6c005..a2cbb9b48 100644
--- a/webapp/components/dot_menu/dot_menu.jsx
+++ b/webapp/components/dot_menu/dot_menu.jsx
@@ -58,10 +58,12 @@ export default class DotMenu extends Component {
     constructor(props) {
         super(props);
 
-        this.handleDropdownOpened = this.handleDropdownOpened.bind(this);
-        this.canDelete = false;
-        this.canEdit = false;
         this.editDisableAction = new DelayedAction(this.handleEditDisable);
+
+        this.state = {
+            canDelete: PostUtils.canDeletePost(props.post),
+            canEdit: PostUtils.canEditPost(props.post, this.editDisableAction)
+        };
     }
 
     componentDidMount() {
@@ -69,7 +71,11 @@ export default class DotMenu extends Component {
         $('#' + this.props.idPrefix + '_dropdown' + this.props.post.id).on('hidden.bs.dropdown', () => this.props.handleDropdownOpened(false));
     }
 
-    handleDropdownOpened() {
+    componentWillUnmount() {
+        this.editDisableAction.cancel();
+    }
+
+    handleDropdownOpened = () => {
         this.props.handleDropdownOpened(true);
 
         const position = $('#post-list').height() - $(this.refs.dropdownToggle).offset().top;
@@ -80,17 +86,15 @@ export default class DotMenu extends Component {
         }
     }
 
-    handleEditDisable() {
-        this.canEdit = false;
+    handleEditDisable = () => {
+        this.setState({canEdit: false});
     }
 
     render() {
         const isSystemMessage = PostUtils.isSystemMessage(this.props.post);
         const isMobile = Utils.isMobile();
-        this.canDelete = PostUtils.canDeletePost(this.props.post);
-        this.canEdit = PostUtils.canEditPost(this.props.post, this.editDisableAction);
 
-        if (this.props.idPrefix === Constants.CENTER && (!isMobile && isSystemMessage && !this.canDelete && !this.canEdit)) {
+        if (this.props.idPrefix === Constants.CENTER && (!isMobile && isSystemMessage && !this.state.canDelete && !this.state.canEdit)) {
             return null;
         }
 
@@ -157,7 +161,7 @@ export default class DotMenu extends Component {
         }
 
         let dotMenuDelete = null;
-        if (this.canDelete) {
+        if (this.state.canDelete) {
             dotMenuDelete = (
                 <DotMenuItem
                     idPrefix={idPrefix + 'Delete'}
@@ -169,7 +173,7 @@ export default class DotMenu extends Component {
         }
 
         let dotMenuEdit = null;
-        if (this.canEdit) {
+        if (this.state.canEdit) {
             dotMenuEdit = (
                 <DotMenuEdit
                     idPrefix={idPrefix + 'Edit'}
-- 
cgit v1.2.3-1-g7c22

