summaryrefslogtreecommitdiffstats
path: root/webapp/components/pending_post_actions.jsx
diff options
context:
space:
mode:
authorsamogot <samogot@gmail.com>2016-05-25 23:13:04 +0300
committerChristopher Speller <crspeller@gmail.com>2016-05-25 16:13:04 -0400
commitd31c972a438e7e9ccc8487f519a915423cb6b93b (patch)
treebf7c535cbb41c75b97d24b85d9f1903605f6d96d /webapp/components/pending_post_actions.jsx
parentdd18b98b0b8c6dfd3011e527367844e8af920edb (diff)
downloadchat-d31c972a438e7e9ccc8487f519a915423cb6b93b.tar.gz
chat-d31c972a438e7e9ccc8487f519a915423cb6b93b.tar.bz2
chat-d31c972a438e7e9ccc8487f519a915423cb6b93b.zip
PLT-1042 allow cancel pending post (#3053)
Diffstat (limited to 'webapp/components/pending_post_actions.jsx')
-rw-r--r--webapp/components/pending_post_actions.jsx92
1 files changed, 92 insertions, 0 deletions
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
+};