Move instances of Client.deletePost() in components to an action (#5129)
Этот коммит содержится в:
коммит произвёл
enahum
родитель
48e1fa8aa0
Коммит
576c662f27
@@ -384,3 +384,30 @@ export function removePostFromStore(post) {
|
|||||||
PostStore.removePost(post);
|
PostStore.removePost(post);
|
||||||
PostStore.emitChange();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,13 +3,9 @@
|
|||||||
|
|
||||||
import $ from 'jquery';
|
import $ from 'jquery';
|
||||||
import ReactDOM from 'react-dom';
|
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 {Modal} from 'react-bootstrap';
|
||||||
import * as AsyncClient from 'utils/async_client.jsx';
|
import ModalStore from 'stores/modal_store.jsx';
|
||||||
import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
|
import {deletePost} from 'actions/post_actions.jsx';
|
||||||
import {removePostFromStore} from 'actions/post_actions.jsx';
|
|
||||||
import Constants from 'utils/constants.jsx';
|
import Constants from 'utils/constants.jsx';
|
||||||
|
|
||||||
import {FormattedMessage} from 'react-intl';
|
import {FormattedMessage} from 'react-intl';
|
||||||
@@ -51,24 +47,16 @@ export default class DeletePostModal extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleDelete() {
|
handleDelete() {
|
||||||
Client.deletePost(
|
deletePost(
|
||||||
this.state.post.channel_id,
|
this.state.post.channel_id,
|
||||||
this.state.post.id,
|
this.state.post,
|
||||||
() => {
|
() => {
|
||||||
removePostFromStore(this.state.post);
|
this.handleHide();
|
||||||
if (this.state.post.id === PostStore.getSelectedPostId()) {
|
|
||||||
AppDispatcher.handleServerAction({
|
|
||||||
type: ActionTypes.RECEIVED_POST_SELECTED,
|
|
||||||
postId: null
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
(err) => {
|
(err) => {
|
||||||
AsyncClient.dispatchError(err, 'deletePost');
|
this.setState({error: err.message});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
this.handleHide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleToggle(value, args) {
|
handleToggle(value, args) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user