From d31c972a438e7e9ccc8487f519a915423cb6b93b Mon Sep 17 00:00:00 2001 From: samogot Date: Wed, 25 May 2016 23:13:04 +0300 Subject: PLT-1042 allow cancel pending post (#3053) --- webapp/components/pending_post_actions.jsx | 92 ++++++++++++++++++++++++++++++ webapp/components/post.jsx | 37 ------------ webapp/components/post_body.jsx | 18 +----- webapp/components/rhs_comment.jsx | 50 +--------------- 4 files changed, 96 insertions(+), 101 deletions(-) create mode 100644 webapp/components/pending_post_actions.jsx (limited to 'webapp/components') 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 ( + + + + {' - '} + + + + ); + } +} + +PendingPostActions.propTypes = { + post: React.PropTypes.object +}; diff --git a/webapp/components/post.jsx b/webapp/components/post.jsx index 084fb9171..2b28d442c 100644 --- a/webapp/components/post.jsx +++ b/webapp/components/post.jsx @@ -4,14 +4,9 @@ import PostHeader from './post_header.jsx'; import PostBody from './post_body.jsx'; -import PostStore from 'stores/post_store.jsx'; -import ChannelStore from 'stores/channel_store.jsx'; - import Constants from 'utils/constants.jsx'; const ActionTypes = Constants.ActionTypes; -import Client from 'utils/web_client.jsx'; -import * as AsyncClient from 'utils/async_client.jsx'; import * as Utils from 'utils/utils.jsx'; import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; @@ -23,7 +18,6 @@ export default class Post extends React.Component { this.handleCommentClick = this.handleCommentClick.bind(this); this.forceUpdateInfo = this.forceUpdateInfo.bind(this); - this.retryPost = this.retryPost.bind(this); this.state = {}; } @@ -44,36 +38,6 @@ export default class Post extends React.Component { this.refs.info.forceUpdate(); this.refs.header.forceUpdate(); } - retryPost(e) { - e.preventDefault(); - - var post = this.props.post; - Client.createPost(post, - (data) => { - AsyncClient.getPosts(); - - 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 = Utils.getTimestamp(); - 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(); - } shouldComponentUpdate(nextProps) { if (!Utils.areObjectsEqual(nextProps.post, this.props.post)) { return true; @@ -245,7 +209,6 @@ export default class Post extends React.Component { parentPost={parentPost} posts={posts} handleCommentClick={this.handleCommentClick} - retryPost={this.retryPost} compactDisplay={this.props.compactDisplay} /> diff --git a/webapp/components/post_body.jsx b/webapp/components/post_body.jsx index ed0a133b3..415052d96 100644 --- a/webapp/components/post_body.jsx +++ b/webapp/components/post_body.jsx @@ -7,6 +7,7 @@ import * as Utils from 'utils/utils.jsx'; import Constants from 'utils/constants.jsx'; import * as TextFormatting from 'utils/text_formatting.jsx'; import PostBodyAdditionalContent from './post_body_additional_content.jsx'; +import PendingPostActions from './pending_post_actions.jsx'; import {FormattedMessage} from 'react-intl'; @@ -28,10 +29,6 @@ export default class PostBody extends React.Component { return true; } - if (nextProps.retryPost.toString() !== this.props.retryPost.toString()) { - return true; - } - if (nextProps.handleCommentClick.toString() !== this.props.handleCommentClick.toString()) { return true; } @@ -114,18 +111,7 @@ export default class PostBody extends React.Component { let loading; if (post.state === Constants.POST_FAILED) { postClass += ' post--fail'; - loading = ( - - - - ); + loading = ; } else if (post.state === Constants.POST_LOADING) { postClass += ' post-waiting'; loading = ( diff --git a/webapp/components/rhs_comment.jsx b/webapp/components/rhs_comment.jsx index 5bd138732..e25e3b524 100644 --- a/webapp/components/rhs_comment.jsx +++ b/webapp/components/rhs_comment.jsx @@ -3,22 +3,18 @@ import UserProfile from './user_profile.jsx'; import FileAttachmentList from './file_attachment_list.jsx'; +import PendingPostActions from './pending_post_actions.jsx'; -import PostStore from 'stores/post_store.jsx'; -import ChannelStore from 'stores/channel_store.jsx'; import TeamStore from 'stores/team_store.jsx'; import UserStore from 'stores/user_store.jsx'; import * as GlobalActions from 'action_creators/global_actions.jsx'; -import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; import * as TextFormatting from 'utils/text_formatting.jsx'; import * as Utils from 'utils/utils.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, FormattedDate} from 'react-intl'; @@ -30,41 +26,10 @@ export default class RhsComment extends React.Component { constructor(props) { super(props); - this.retryComment = this.retryComment.bind(this); this.handlePermalink = this.handlePermalink.bind(this); this.state = {}; } - retryComment(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(); - } handlePermalink(e) { e.preventDefault(); GlobalActions.showGetPostLinkModal(this.props.post); @@ -198,18 +163,7 @@ export default class RhsComment extends React.Component { if (post.state === Constants.POST_FAILED) { postClass += ' post-fail'; - loading = ( - - - - ); + loading = ; } else if (post.state === Constants.POST_LOADING) { postClass += ' post-waiting'; loading = ( -- cgit v1.2.3-1-g7c22