2016-08-08 11:18:21 +09:00
|
|
|
import Telescope from 'meteor/nova:lib';
|
2016-04-19 15:45:36 +09:00
|
|
|
import React from 'react';
|
2016-06-09 17:42:20 +09:00
|
|
|
import {FormattedMessage } from 'react-intl';
|
2016-11-29 14:08:24 +01:00
|
|
|
import { ModalTrigger, withList } from 'meteor/nova:core';
|
|
|
|
import { withCurrentUser } from 'meteor/nova:users';
|
2016-11-11 16:42:19 +09:00
|
|
|
import Comments from 'meteor/nova:comments';
|
2016-11-23 11:07:48 +09:00
|
|
|
import gql from 'graphql-tag';
|
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-11-23 11:07:48 +09:00
|
|
|
const {loading, terms: { postId }, results} = props;
|
2016-11-11 16:42:19 +09:00
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
|
|
|
|
return <div className="posts-comments-thread"><Telescope.components.Loading/></div>
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
const commentCount = results.length;
|
|
|
|
|
|
|
|
const resultsClone = _.map(results, _.clone); // we don't want to modify the objects we got from props
|
|
|
|
const nestedComments = Telescope.utils.unflatten(resultsClone, '_id', 'parentCommentId');
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="posts-comments-thread">
|
|
|
|
<h4 className="posts-comments-thread-title"><FormattedMessage id="comments.comments"/></h4>
|
|
|
|
<Telescope.components.CommentsList comments={nestedComments} commentCount={commentCount}/>
|
2016-11-15 18:33:16 +01:00
|
|
|
{ props.currentUser ?
|
2016-11-11 16:42:19 +09:00
|
|
|
<div className="posts-comments-thread-new">
|
|
|
|
<h4><FormattedMessage id="comments.new"/></h4>
|
|
|
|
<Telescope.components.CommentsNewForm
|
|
|
|
postId={postId}
|
|
|
|
type="comment"
|
|
|
|
/>
|
|
|
|
</div> :
|
|
|
|
<div>
|
|
|
|
<ModalTrigger size="small" component={<a><FormattedMessage id="comments.please_log_in"/></a>}>
|
|
|
|
<Telescope.components.UsersAccountForm/>
|
|
|
|
</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-30 10:50:04 +09:00
|
|
|
PostsCommentsThread.fragmentName = 'commentsListFragment';
|
|
|
|
PostsCommentsThread.fragment = gql`
|
2016-11-23 11:07:48 +09:00
|
|
|
fragment commentsListFragment on Comment {
|
|
|
|
_id
|
|
|
|
postId
|
|
|
|
parentCommentId
|
|
|
|
topLevelCommentId
|
|
|
|
body
|
|
|
|
htmlBody
|
|
|
|
postedAt
|
|
|
|
user {
|
|
|
|
_id
|
|
|
|
__displayName
|
|
|
|
__emailHash
|
|
|
|
__slug
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const options = {
|
2016-11-19 20:01:17 +01:00
|
|
|
collection: Comments,
|
2016-11-23 11:07:48 +09:00
|
|
|
queryName: 'commentsListQuery',
|
2016-11-30 10:50:04 +09:00
|
|
|
fragmentName: PostsCommentsThread.fragmentName,
|
|
|
|
fragment: PostsCommentsThread.fragment,
|
2016-11-19 20:01:17 +01:00
|
|
|
};
|
|
|
|
|
2016-11-23 11:07:48 +09:00
|
|
|
Telescope.registerComponent('PostsCommentsThread', PostsCommentsThread, withCurrentUser, withList(options));
|