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
@@ -272,3 +272,37 @@ export function removeReaction(channelId, postId, emojiName) {
|
|||||||
|
|
||||||
AsyncClient.deleteReaction(channelId, reaction);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
import $ from 'jquery';
|
import $ from 'jquery';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
|
import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
|
||||||
import Client from 'client/web_client.jsx';
|
|
||||||
import EmojiStore from 'stores/emoji_store.jsx';
|
import EmojiStore from 'stores/emoji_store.jsx';
|
||||||
import UserStore from 'stores/user_store.jsx';
|
import UserStore from 'stores/user_store.jsx';
|
||||||
import PostDeletedModal from './post_deleted_modal.jsx';
|
import PostDeletedModal from './post_deleted_modal.jsx';
|
||||||
@@ -163,24 +162,16 @@ export default class CreateComment extends React.Component {
|
|||||||
post.create_at = time;
|
post.create_at = time;
|
||||||
|
|
||||||
GlobalActions.emitUserCommentedEvent(post);
|
GlobalActions.emitUserCommentedEvent(post);
|
||||||
Client.createPost(
|
|
||||||
post,
|
|
||||||
(data) => {
|
|
||||||
PostStore.removePendingPost(post.channel_id, post.pending_post_id);
|
|
||||||
|
|
||||||
AppDispatcher.handleServerAction({
|
PostActions.createPost(post, false,
|
||||||
type: ActionTypes.RECEIVED_POST,
|
() => {
|
||||||
post: data
|
// DO nothing.
|
||||||
});
|
|
||||||
},
|
},
|
||||||
(err) => {
|
(err) => {
|
||||||
if (err.id === 'api.post.create_post.root_id.app_error') {
|
if (err.id === 'api.post.create_post.root_id.app_error') {
|
||||||
this.showPostDeletedModal();
|
this.showPostDeletedModal();
|
||||||
|
|
||||||
PostStore.removePendingPost(post.channel_id, post.pending_post_id);
|
|
||||||
} else {
|
} else {
|
||||||
post.state = Constants.POST_FAILED;
|
this.forceUpdate();
|
||||||
PostStore.updatePendingPost(post);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -188,6 +179,18 @@ export default class CreateComment extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
message: '',
|
||||||
|
submitting: false,
|
||||||
|
postError: null,
|
||||||
|
fileInfos: [],
|
||||||
|
serverError: null
|
||||||
|
});
|
||||||
|
|
||||||
|
const fasterThanHumanWillClick = 150;
|
||||||
|
const forceFocus = (Date.now() - this.state.lastBlurAt < fasterThanHumanWillClick);
|
||||||
|
this.focusTextbox(forceFocus);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSubmitReaction(isReaction) {
|
handleSubmitReaction(isReaction) {
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import TutorialTip from './tutorial/tutorial_tip.jsx';
|
|||||||
|
|
||||||
import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
|
import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
|
||||||
import * as GlobalActions from 'actions/global_actions.jsx';
|
import * as GlobalActions from 'actions/global_actions.jsx';
|
||||||
import Client from 'client/web_client.jsx';
|
|
||||||
import * as Utils from 'utils/utils.jsx';
|
import * as Utils from 'utils/utils.jsx';
|
||||||
import * as UserAgent from 'utils/user_agent.jsx';
|
import * as UserAgent from 'utils/user_agent.jsx';
|
||||||
import * as ChannelActions from 'actions/channel_actions.jsx';
|
import * as ChannelActions from 'actions/channel_actions.jsx';
|
||||||
@@ -158,24 +157,16 @@ export default class CreatePost extends React.Component {
|
|||||||
|
|
||||||
GlobalActions.emitUserPostedEvent(post);
|
GlobalActions.emitUserPostedEvent(post);
|
||||||
|
|
||||||
Client.createPost(post,
|
PostActions.createPost(post, false,
|
||||||
(data) => {
|
() => {
|
||||||
PostStore.removePendingPost(post.pending_post_id);
|
// DO nothing.
|
||||||
|
|
||||||
AppDispatcher.handleServerAction({
|
|
||||||
type: ActionTypes.RECEIVED_POST,
|
|
||||||
post: data
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
(err) => {
|
(err) => {
|
||||||
if (err.id === 'api.post.create_post.root_id.app_error') {
|
if (err.id === 'api.post.create_post.root_id.app_error') {
|
||||||
// this should never actually happen since you can't reply from this textbox
|
// this should never actually happen since you can't reply from this textbox
|
||||||
this.showPostDeletedModal();
|
this.showPostDeletedModal();
|
||||||
|
|
||||||
PostStore.removePendingPost(post.pending_post_id);
|
|
||||||
} else {
|
} else {
|
||||||
post.state = Constants.POST_FAILED;
|
this.forceUpdate();
|
||||||
PostStore.updatePendingPost(post);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
|
|||||||
@@ -2,14 +2,10 @@
|
|||||||
// See License.txt for license information.
|
// See License.txt for license information.
|
||||||
|
|
||||||
import PostStore from 'stores/post_store.jsx';
|
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';
|
import Constants from 'utils/constants.jsx';
|
||||||
const ActionTypes = Constants.ActionTypes;
|
|
||||||
|
|
||||||
import {FormattedMessage} from 'react-intl';
|
import {FormattedMessage} from 'react-intl';
|
||||||
|
|
||||||
@@ -26,25 +22,20 @@ export default class PendingPostOptions extends React.Component {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
var post = this.props.post;
|
var post = this.props.post;
|
||||||
Client.createPost(post,
|
createPost(post, true,
|
||||||
(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
|
|
||||||
});
|
|
||||||
},
|
|
||||||
() => {
|
() => {
|
||||||
post.state = Constants.POST_FAILED;
|
// DO nothing.
|
||||||
PostStore.updatePendingPost(post);
|
},
|
||||||
this.forceUpdate();
|
(err) => {
|
||||||
|
if (err.id === 'api.post.create_post.root_id.app_error') {
|
||||||
|
this.showPostDeletedModal();
|
||||||
|
} else {
|
||||||
|
this.forceUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
submitting: false
|
||||||
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user