Files
mattermost/web/react/components/post.jsx

124 lines
4.6 KiB
React
Raw Normal View History

2015-06-14 23:53:32 -08:00
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
// See License.txt for license information.
var PostHeader = require('./post_header.jsx');
var PostBody = require('./post_body.jsx');
var PostInfo = require('./post_info.jsx');
var AppDispatcher = require('../dispatcher/app_dispatcher.jsx');
var Constants = require('../utils/constants.jsx');
var UserStore = require('../stores/user_store.jsx');
2015-07-23 09:39:29 -04:00
var PostStore = require('../stores/post_store.jsx');
var ChannelStore = require('../stores/channel_store.jsx');
var client = require('../utils/client.jsx');
var AsyncClient = require('../utils/async_client.jsx');
2015-06-14 23:53:32 -08:00
var ActionTypes = Constants.ActionTypes;
module.exports = React.createClass({
2015-07-11 08:32:02 -07:00
displayName: "Post",
2015-06-14 23:53:32 -08:00
handleCommentClick: function(e) {
e.preventDefault();
2015-07-11 08:32:02 -07:00
var data = {};
2015-06-14 23:53:32 -08:00
data.order = [this.props.post.id];
data.posts = this.props.posts;
AppDispatcher.handleServerAction({
type: ActionTypes.RECIEVED_POST_SELECTED,
post_list: data
});
AppDispatcher.handleServerAction({
type: ActionTypes.RECIEVED_SEARCH,
results: null
});
},
forceUpdateInfo: function() {
this.refs.info.forceUpdate();
this.refs.header.forceUpdate();
},
2015-07-23 09:39:29 -04:00
retryPost: function(e) {
e.preventDefault();
var post = this.props.post;
client.createPost(post, post.channel_id,
function(data) {
AsyncClient.getPosts(true);
var channel = ChannelStore.get(post.channel_id);
2015-07-23 09:39:29 -04:00
var member = ChannelStore.getMember(post.channel_id);
member.msg_count = channel.total_msg_count;
member.last_viewed_at = (new Date).getTime();
ChannelStore.setChannelMember(member);
AppDispatcher.handleServerAction({
type: ActionTypes.RECIEVED_POST,
post: data
});
2015-07-23 09:39:29 -04:00
}.bind(this),
function(err) {
post.state = Constants.POST_FAILED;
2015-07-23 09:39:29 -04:00
PostStore.updatePendingPost(post);
this.forceUpdate();
}.bind(this)
);
post.state = Constants.POST_LOADING;
2015-07-23 09:39:29 -04:00
PostStore.updatePendingPost(post);
this.forceUpdate();
},
2015-06-14 23:53:32 -08:00
getInitialState: function() {
return { };
},
render: function() {
var post = this.props.post;
var parentPost = this.props.parentPost;
var posts = this.props.posts;
var type = 'Post';
if (post.root_id && post.root_id.length > 0) {
type = 'Comment';
2015-06-14 23:53:32 -08:00
}
var commentCount = 0;
var commentRootId = parentPost ? post.root_id : post.id;
for (var postId in posts) {
if (posts[postId].root_id == commentRootId) {
commentCount += 1;
}
}
var error = this.state.error ? <div className='form-group has-error'><label className='control-label'>{ this.state.error }</label></div> : null;
2015-07-11 08:32:02 -07:00
var rootUser = this.props.sameRoot ? "same--root" : "other--root";
2015-06-14 23:53:32 -08:00
var postType = "";
if (type != "Post"){
2015-06-14 23:53:32 -08:00
postType = "post--comment";
}
var currentUserCss = "";
if (UserStore.getCurrentId() === post.user_id) {
currentUserCss = "current--user";
}
var timestamp = UserStore.getCurrentUser().update_at;
2015-06-14 23:53:32 -08:00
return (
<div>
<div id={post.id} className={"post " + this.props.sameUser + " " + rootUser + " " + postType + " " + currentUserCss}>
2015-06-14 23:53:32 -08:00
{ !this.props.hideProfilePic ?
<div className="post-profile-img__container">
<img className="post-profile-img" src={"/api/v1/users/" + post.user_id + "/image?time=" + timestamp} height="36" width="36" />
2015-06-14 23:53:32 -08:00
</div>
2015-07-11 08:32:02 -07:00
: null }
<div className="post__content">
<PostHeader ref="header" post={post} sameRoot={this.props.sameRoot} commentCount={commentCount} handleCommentClick={this.handleCommentClick} isLastComment={this.props.isLastComment} />
2015-07-23 09:39:29 -04:00
<PostBody post={post} sameRoot={this.props.sameRoot} parentPost={parentPost} posts={posts} handleCommentClick={this.handleCommentClick} retryPost={this.retryPost} />
<PostInfo ref="info" post={post} sameRoot={this.props.sameRoot} commentCount={commentCount} handleCommentClick={this.handleCommentClick} allowReply="true" />
2015-06-14 23:53:32 -08:00
</div>
</div>
</div>
);
}
});