Move instances of Client.createPost() in components to an action (#4639)

* Move instances of Client.createPost() in components to an action

* update per review, waiting for more review and see if this is the right way

* update per code review

* update code

* remove comment per request
Этот коммит содержится в:
Carlos Tadeu Panato Junior
2016-12-05 18:59:12 +01:00
коммит произвёл Harrison Healey
родитель b9b986b741
Коммит f27aca4b73
4 изменённых файлов: 68 добавлений и 49 удалений

Просмотреть файл

@@ -272,3 +272,37 @@ export function removeReaction(channelId, postId, emojiName) {
AsyncClient.deleteReaction(channelId, reaction);
}
export function createPost(post, doLoadPost, success, error) {
Client.createPost(post,
(data) => {
if (doLoadPost) {
loadPosts(post.channel_id);
} else {
PostStore.removePendingPost(post.pending_post_id);
}
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_POST,
post: data
});
if (success) {
success(data);
}
},
(err) => {
if (err.id === 'api.post.create_post.root_id.app_error') {
PostStore.removePendingPost(post.pending_post_id);
} else {
post.state = Constants.POST_FAILED;
PostStore.updatePendingPost(post);
}
if (error) {
error(err);
}
}
);
}