2016-11-07 23:46:12 +09:00
|
|
|
import Telescope from 'meteor/nova:lib';
|
|
|
|
import React, { PropTypes, Component } from 'react';
|
|
|
|
import Posts from "meteor/nova:posts";
|
|
|
|
import Comments from "meteor/nova:comments";
|
|
|
|
|
|
|
|
import { graphql } from 'react-apollo';
|
|
|
|
import gql from 'graphql-tag';
|
|
|
|
|
|
|
|
class CommentsListContainer extends Component {
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
2016-11-07 16:46:55 +01:00
|
|
|
const {loading, results, componentProps} = this.props;
|
2016-11-07 23:46:12 +09:00
|
|
|
const Component = this.props.component;
|
2016-11-07 16:33:52 +01:00
|
|
|
//const hasMore = comments && commentsViewTotal && comments.length < commentsViewTotal;
|
2016-11-07 23:46:12 +09:00
|
|
|
|
|
|
|
return loading ? <Telescope.components.Loading/> : <Component
|
2016-11-07 16:46:55 +01:00
|
|
|
results={results || []}
|
|
|
|
//count={comments && comments.length}
|
|
|
|
{...componentProps}
|
2016-11-07 16:33:52 +01:00
|
|
|
/>;
|
2016-11-07 23:46:12 +09:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
CommentsListContainer.propTypes = {
|
|
|
|
loading: React.PropTypes.bool,
|
|
|
|
};
|
|
|
|
|
|
|
|
CommentsListContainer.displayName = "CommentsListContainer";
|
|
|
|
|
|
|
|
const CommentsListContainerWithData = graphql(gql`
|
|
|
|
query getCommentsView ($postId: String) {
|
|
|
|
comments (postId: $postId) {
|
|
|
|
_id
|
|
|
|
postId
|
|
|
|
parentCommentId
|
|
|
|
topLevelCommentId
|
|
|
|
body
|
|
|
|
htmlBody
|
|
|
|
postedAt
|
|
|
|
user {
|
|
|
|
_id
|
|
|
|
telescope {
|
|
|
|
slug
|
|
|
|
emailHash # used for the avatar
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, {
|
|
|
|
options(ownProps) {
|
|
|
|
return {
|
|
|
|
variables: {
|
|
|
|
postId: ownProps.postId
|
|
|
|
},
|
|
|
|
// pollInterval: 20000,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
props(props) {
|
2016-11-07 16:33:52 +01:00
|
|
|
const {data: {loading, comments}} = props;
|
2016-11-07 23:46:12 +09:00
|
|
|
return {
|
|
|
|
loading,
|
2016-11-07 16:46:55 +01:00
|
|
|
results: comments,
|
2016-11-07 16:33:52 +01:00
|
|
|
// loadMore() {
|
|
|
|
// // basically, rerun the query 'getPostsView' with a new offset
|
|
|
|
// return fetchMore({
|
|
|
|
// variables: { offset: posts.length },
|
|
|
|
// updateQuery(previousResults, { fetchMoreResult }) {
|
|
|
|
// // no more post to fetch
|
|
|
|
// if (!fetchMoreResult.data) {
|
|
|
|
// return previousResults;
|
|
|
|
// }
|
|
|
|
// // return the previous results "augmented" with more
|
|
|
|
// return {...previousResults, posts: [...previousResults.posts, ...fetchMoreResult.data.posts]};
|
|
|
|
// },
|
|
|
|
// });
|
|
|
|
// },
|
2016-11-07 23:46:12 +09:00
|
|
|
};
|
|
|
|
},
|
|
|
|
})(CommentsListContainer);
|
|
|
|
|
|
|
|
module.exports = CommentsListContainerWithData;
|