2016-04-19 15:45:36 +09:00
|
|
|
import React from 'react';
|
2016-12-21 18:14:13 +01:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2017-03-23 16:27:59 +09:00
|
|
|
import { ModalTrigger, withList, withCurrentUser, Components, registerComponent, Utils } from 'meteor/vulcan:core';
|
|
|
|
import Comments from 'meteor/vulcan:comments';
|
2016-11-15 18:33:16 +01:00
|
|
|
|
2016-11-07 23:46:12 +09:00
|
|
|
const PostsCommentsThread = (props, context) => {
|
2016-04-19 15:45:36 +09:00
|
|
|
|
2016-12-21 18:14:13 +01:00
|
|
|
const {loading, terms: { postId }, results, totalCount} = props;
|
|
|
|
|
2016-11-11 16:42:19 +09:00
|
|
|
if (loading) {
|
|
|
|
|
2016-12-06 18:06:29 +01:00
|
|
|
return <div className="posts-comments-thread"><Components.Loading/></div>
|
2016-11-11 16:42:19 +09:00
|
|
|
|
|
|
|
} else {
|
2016-12-21 18:14:13 +01:00
|
|
|
|
2016-11-11 16:42:19 +09:00
|
|
|
const resultsClone = _.map(results, _.clone); // we don't want to modify the objects we got from props
|
2016-12-12 11:34:28 +09:00
|
|
|
const nestedComments = Utils.unflatten(resultsClone, '_id', 'parentCommentId');
|
2016-11-11 16:42:19 +09:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="posts-comments-thread">
|
|
|
|
<h4 className="posts-comments-thread-title"><FormattedMessage id="comments.comments"/></h4>
|
2016-12-21 18:14:13 +01:00
|
|
|
<Components.CommentsList comments={nestedComments} commentCount={totalCount}/>
|
|
|
|
{!!props.currentUser ?
|
2016-11-11 16:42:19 +09:00
|
|
|
<div className="posts-comments-thread-new">
|
|
|
|
<h4><FormattedMessage id="comments.new"/></h4>
|
2016-12-06 18:06:29 +01:00
|
|
|
<Components.CommentsNewForm
|
2016-11-11 16:42:19 +09:00
|
|
|
postId={postId}
|
|
|
|
type="comment"
|
|
|
|
/>
|
|
|
|
</div> :
|
|
|
|
<div>
|
|
|
|
<ModalTrigger size="small" component={<a><FormattedMessage id="comments.please_log_in"/></a>}>
|
2016-12-06 18:06:29 +01:00
|
|
|
<Components.UsersAccountForm/>
|
2016-11-11 16:42:19 +09:00
|
|
|
</ModalTrigger>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2016-04-19 15:45:36 +09:00
|
|
|
};
|
|
|
|
|
2016-05-22 16:42:24 +09:00
|
|
|
PostsCommentsThread.displayName = "PostsCommentsThread";
|
|
|
|
|
2016-11-15 18:33:16 +01:00
|
|
|
PostsCommentsThread.propTypes = {
|
2016-10-14 08:47:18 +02:00
|
|
|
currentUser: React.PropTypes.object
|
|
|
|
};
|
|
|
|
|
2016-11-23 11:07:48 +09:00
|
|
|
const options = {
|
2016-11-19 20:01:17 +01:00
|
|
|
collection: Comments,
|
2016-11-23 11:07:48 +09:00
|
|
|
queryName: 'commentsListQuery',
|
2017-01-30 19:46:48 +09:00
|
|
|
fragmentName: 'CommentsList',
|
2017-01-12 17:30:25 +09:00
|
|
|
limit: 0,
|
2016-11-19 20:01:17 +01:00
|
|
|
};
|
|
|
|
|
2017-01-30 19:46:48 +09:00
|
|
|
registerComponent('PostsCommentsThread', PostsCommentsThread, [withList, options], withCurrentUser);
|