Vulcan/packages/vulcan-base-components/lib/posts/PostsCommentsThread.jsx

57 lines
1.8 KiB
React
Raw Normal View History

import React from 'react';
2017-05-19 14:42:43 -06:00
import PropTypes from 'prop-types';
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
2017-05-19 14:42:43 -06:00
const PostsCommentsThread = (props, /* context*/) => {
const {loading, terms: { postId }, results, totalCount} = props;
if (loading) {
return <div className="posts-comments-thread"><Components.Loading/></div>
} else {
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');
return (
<div className="posts-comments-thread">
<h4 className="posts-comments-thread-title"><FormattedMessage id="comments.comments"/></h4>
<Components.CommentsList comments={nestedComments} commentCount={totalCount}/>
{!!props.currentUser ?
<div className="posts-comments-thread-new">
<h4><FormattedMessage id="comments.new"/></h4>
<Components.CommentsNewForm
postId={postId}
type="comment"
/>
</div> :
<div>
<ModalTrigger size="small" component={<a><FormattedMessage id="comments.please_log_in"/></a>}>
<Components.UsersAccountForm/>
</ModalTrigger>
</div>
}
</div>
);
}
};
2017-05-19 14:42:43 -06:00
PostsCommentsThread.displayName = 'PostsCommentsThread';
2016-11-15 18:33:16 +01:00
PostsCommentsThread.propTypes = {
2017-05-19 14:42:43 -06:00
currentUser: PropTypes.object
};
2016-11-23 11:07:48 +09:00
const options = {
collection: Comments,
2016-11-23 11:07:48 +09:00
queryName: 'commentsListQuery',
fragmentName: 'CommentsList',
limit: 0,
};
registerComponent('PostsCommentsThread', PostsCommentsThread, [withList, options], withCurrentUser);