forked from VulcanJS/Vulcan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostsCommentsThread.jsx
55 lines (44 loc) · 1.76 KB
/
PostsCommentsThread.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import React from 'react';
import { FormattedMessage } from 'react-intl';
import { ModalTrigger, withList, withCurrentUser, Components, registerComponent, Utils } from 'meteor/nova:core';
import Comments from 'meteor/nova:comments';
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
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>
);
}
};
PostsCommentsThread.displayName = "PostsCommentsThread";
PostsCommentsThread.propTypes = {
currentUser: React.PropTypes.object
};
const options = {
collection: Comments,
queryName: 'commentsListQuery',
fragmentName: 'CommentsList',
limit: 0,
};
registerComponent('PostsCommentsThread', PostsCommentsThread, [withList, options], withCurrentUser);