From 576c662f27d237e1f173d331aade6ab697911395 Mon Sep 17 00:00:00 2001 From: Carlos Tadeu Panato Junior Date: Fri, 20 Jan 2017 03:03:47 +0100 Subject: Move instances of Client.deletePost() in components to an action (#5129) --- webapp/actions/post_actions.jsx | 27 +++++++++++++++++++++++++++ webapp/components/delete_post_modal.jsx | 24 ++++++------------------ 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/webapp/actions/post_actions.jsx b/webapp/actions/post_actions.jsx index 4d472db45..7179b6365 100644 --- a/webapp/actions/post_actions.jsx +++ b/webapp/actions/post_actions.jsx @@ -384,3 +384,30 @@ export function removePostFromStore(post) { PostStore.removePost(post); PostStore.emitChange(); } + +export function deletePost(channelId, post, success, error) { + Client.deletePost( + channelId, + post.id, + () => { + removePostFromStore(post); + if (post.id === PostStore.getSelectedPostId()) { + AppDispatcher.handleServerAction({ + type: ActionTypes.RECEIVED_POST_SELECTED, + postId: null + }); + } + + if (success) { + success(); + } + }, + (err) => { + AsyncClient.dispatchError(err, 'deletePost'); + + if (error) { + error(err); + } + } + ); +} diff --git a/webapp/components/delete_post_modal.jsx b/webapp/components/delete_post_modal.jsx index 84eef4671..39d4f41f9 100644 --- a/webapp/components/delete_post_modal.jsx +++ b/webapp/components/delete_post_modal.jsx @@ -3,13 +3,9 @@ import $ from 'jquery'; import ReactDOM from 'react-dom'; -import Client from 'client/web_client.jsx'; -import PostStore from 'stores/post_store.jsx'; -import ModalStore from 'stores/modal_store.jsx'; import {Modal} from 'react-bootstrap'; -import * as AsyncClient from 'utils/async_client.jsx'; -import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; -import {removePostFromStore} from 'actions/post_actions.jsx'; +import ModalStore from 'stores/modal_store.jsx'; +import {deletePost} from 'actions/post_actions.jsx'; import Constants from 'utils/constants.jsx'; import {FormattedMessage} from 'react-intl'; @@ -51,24 +47,16 @@ export default class DeletePostModal extends React.Component { } handleDelete() { - Client.deletePost( + deletePost( this.state.post.channel_id, - this.state.post.id, + this.state.post, () => { - removePostFromStore(this.state.post); - if (this.state.post.id === PostStore.getSelectedPostId()) { - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_POST_SELECTED, - postId: null - }); - } + this.handleHide(); }, (err) => { - AsyncClient.dispatchError(err, 'deletePost'); + this.setState({error: err.message}); } ); - - this.handleHide(); } handleToggle(value, args) { -- cgit v1.2.3-1-g7c22