mirror of
https://github.com/vale981/Vulcan
synced 2025-03-10 12:36:39 -04:00
56 lines
1.9 KiB
JavaScript
56 lines
1.9 KiB
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { FormattedMessage } from 'meteor/vulcan:i18n';
|
|
import { withList, withCurrentUser, Components, registerComponent, Utils } from 'meteor/vulcan:core';
|
|
import { Comments } from '../../modules/comments/index.js';
|
|
|
|
const PostsCommentsThread = (props, /* context*/) => {
|
|
|
|
const {loading, terms: { postId }, results, totalCount, currentUser} = 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
|
|
const nestedComments = Utils.unflatten(resultsClone, {idProperty: '_id', parentIdProperty: 'parentCommentId'});
|
|
|
|
return (
|
|
<div className="posts-comments-thread">
|
|
<h4 className="posts-comments-thread-title"><FormattedMessage id="comments.comments"/></h4>
|
|
<Components.CommentsList currentUser={currentUser} comments={nestedComments} commentCount={totalCount}/>
|
|
{!!currentUser ?
|
|
<div className="posts-comments-thread-new">
|
|
<h4><FormattedMessage id="comments.new"/></h4>
|
|
<Components.CommentsNewForm
|
|
postId={postId}
|
|
type="comment"
|
|
/>
|
|
</div> :
|
|
<div>
|
|
<Components.ModalTrigger size="small" component={<a href="#"><FormattedMessage id="comments.please_log_in"/></a>}>
|
|
<Components.AccountsLoginForm/>
|
|
</Components.ModalTrigger>
|
|
</div>
|
|
}
|
|
</div>
|
|
);
|
|
}
|
|
};
|
|
|
|
PostsCommentsThread.displayName = 'PostsCommentsThread';
|
|
|
|
PostsCommentsThread.propTypes = {
|
|
currentUser: PropTypes.object
|
|
};
|
|
|
|
const options = {
|
|
collection: Comments,
|
|
queryName: 'commentsListQuery',
|
|
fragmentName: 'CommentsList',
|
|
limit: 0,
|
|
};
|
|
|
|
registerComponent('PostsCommentsThread', PostsCommentsThread, [withList, options], withCurrentUser);
|