2016-04-19 15:45:36 +09:00
|
|
|
import React from 'react';
|
2017-05-19 14:42:43 -06:00
|
|
|
import PropTypes from 'prop-types';
|
2017-06-01 11:42:30 +09:00
|
|
|
import { FormattedMessage } from 'meteor/vulcan:i18n';
|
2017-04-28 09:25:29 +09:00
|
|
|
import { withList, withCurrentUser, Components, registerComponent, Utils } from 'meteor/vulcan:core';
|
2017-03-23 16:27:59 +09:00
|
|
|
import Comments from 'meteor/vulcan:comments';
|
2016-11-15 18:33:16 +01:00
|
|
|
|
2017-05-19 14:42:43 -06: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
|
2017-05-06 16:12:44 +09:00
|
|
|
const nestedComments = Utils.unflatten(resultsClone, {idProperty: '_id', parentIdProperty: '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>
|
2017-04-30 20:32:06 +09:00
|
|
|
<Components.ModalTrigger size="small" component={<a href="#"><FormattedMessage id="comments.please_log_in"/></a>}>
|
2017-04-28 09:25:29 +09:00
|
|
|
<Components.AccountsLoginForm/>
|
|
|
|
</Components.ModalTrigger>
|
2016-11-11 16:42:19 +09:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2016-04-19 15:45:36 +09:00
|
|
|
};
|
|
|
|
|
2017-05-19 14:42:43 -06:00
|
|
|
PostsCommentsThread.displayName = 'PostsCommentsThread';
|
2016-05-22 16:42:24 +09:00
|
|
|
|
2016-11-15 18:33:16 +01:00
|
|
|
PostsCommentsThread.propTypes = {
|
2017-05-19 14:42:43 -06:00
|
|
|
currentUser: PropTypes.object
|
2016-10-14 08:47:18 +02:00
|
|
|
};
|
|
|
|
|
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);
|