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
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
b9b986b741
Коммит
f27aca4b73
@@ -2,14 +2,10 @@
|
||||
// See License.txt for license information.
|
||||
|
||||
import PostStore from 'stores/post_store.jsx';
|
||||
import ChannelStore from 'stores/channel_store.jsx';
|
||||
|
||||
import {loadPosts} from 'actions/post_actions.jsx';
|
||||
import {createPost} from 'actions/post_actions.jsx';
|
||||
|
||||
import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
|
||||
import Client from 'client/web_client.jsx';
|
||||
import Constants from 'utils/constants.jsx';
|
||||
const ActionTypes = Constants.ActionTypes;
|
||||
|
||||
import {FormattedMessage} from 'react-intl';
|
||||
|
||||
@@ -26,25 +22,20 @@ export default class PendingPostOptions extends React.Component {
|
||||
e.preventDefault();
|
||||
|
||||
var post = this.props.post;
|
||||
Client.createPost(post,
|
||||
(data) => {
|
||||
loadPosts(post.channel_id);
|
||||
|
||||
var channel = ChannelStore.get(post.channel_id);
|
||||
var member = ChannelStore.getMyMember(post.channel_id);
|
||||
member.msg_count = channel.total_msg_count;
|
||||
member.last_viewed_at = (new Date()).getTime();
|
||||
ChannelStore.storeMyChannelMember(member);
|
||||
|
||||
AppDispatcher.handleServerAction({
|
||||
type: ActionTypes.RECEIVED_POST,
|
||||
post: data
|
||||
});
|
||||
},
|
||||
createPost(post, true,
|
||||
() => {
|
||||
post.state = Constants.POST_FAILED;
|
||||
PostStore.updatePendingPost(post);
|
||||
this.forceUpdate();
|
||||
// DO nothing.
|
||||
},
|
||||
(err) => {
|
||||
if (err.id === 'api.post.create_post.root_id.app_error') {
|
||||
this.showPostDeletedModal();
|
||||
} else {
|
||||
this.forceUpdate();
|
||||
}
|
||||
|
||||
this.setState({
|
||||
submitting: false
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user