From d31c972a438e7e9ccc8487f519a915423cb6b93b Mon Sep 17 00:00:00 2001
From: samogot <samogot@gmail.com>
Date: Wed, 25 May 2016 23:13:04 +0300
Subject: PLT-1042 allow cancel pending post (#3053)

---
 webapp/components/pending_post_actions.jsx | 92 ++++++++++++++++++++++++++++++
 1 file changed, 92 insertions(+)
 create mode 100644 webapp/components/pending_post_actions.jsx

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

diff --git a/webapp/components/pending_post_actions.jsx b/webapp/components/pending_post_actions.jsx
new file mode 100644
index 000000000..7528ef207
--- /dev/null
+++ b/webapp/components/pending_post_actions.jsx
@@ -0,0 +1,92 @@
+// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+import PostStore from 'stores/post_store.jsx';
+import ChannelStore from 'stores/channel_store.jsx';
+
+import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
+
+import Client from 'utils/web_client.jsx';
+import * as AsyncClient from 'utils/async_client.jsx';
+
+import Constants from 'utils/constants.jsx';
+const ActionTypes = Constants.ActionTypes;
+
+import {FormattedMessage} from 'react-intl';
+
+import React from 'react';
+
+export default class PendingPostActions extends React.Component {
+    constructor(props) {
+        super(props);
+        this.retryPost = this.retryPost.bind(this);
+        this.cancelPost = this.cancelPost.bind(this);
+        this.state = {};
+    }
+    retryPost(e) {
+        e.preventDefault();
+
+        var post = this.props.post;
+        Client.createPost(post,
+            (data) => {
+                AsyncClient.getPosts(post.channel_id);
+
+                var channel = ChannelStore.get(post.channel_id);
+                var member = ChannelStore.getMember(post.channel_id);
+                member.msg_count = channel.total_msg_count;
+                member.last_viewed_at = (new Date()).getTime();
+                ChannelStore.setChannelMember(member);
+
+                AppDispatcher.handleServerAction({
+                    type: ActionTypes.RECEIVED_POST,
+                    post: data
+                });
+            },
+            () => {
+                post.state = Constants.POST_FAILED;
+                PostStore.updatePendingPost(post);
+                this.forceUpdate();
+            }
+        );
+
+        post.state = Constants.POST_LOADING;
+        PostStore.updatePendingPost(post);
+        this.forceUpdate();
+    }
+    cancelPost(e) {
+        e.preventDefault();
+
+        var post = this.props.post;
+        PostStore.removePendingPost(post.channel_id, post.pending_post_id);
+        this.forceUpdate();
+    }
+    render() {
+        return (<span className='pending-post-actions'>
+            <a
+                className='post-retry'
+                href='#'
+                onClick={this.retryPost}
+            >
+                <FormattedMessage
+                    id='pending_post_actions.retry'
+                    defaultMessage='Retry'
+                />
+            </a>
+            {' - '}
+            <a
+                className='post-cancel'
+                href='#'
+                onClick={this.cancelPost}
+            >
+                <FormattedMessage
+                    id='pending_post_actions.cancel'
+                    defaultMessage='Cancel'
+                />
+            </a>
+        </span>);
+    }
+}
+
+PendingPostActions.propTypes = {
+    post: React.PropTypes.object
+};
-- 
cgit v1.2.3-1-g7c22

