import Telescope from 'meteor/nova:lib';
import React from 'react';
import { withList } from 'meteor/nova:core';
import Posts from 'meteor/nova:posts';
import gql from 'graphql-tag';
const PostsList = (props) => {
const {results, terms, loading, count, totalCount, loadMore, showHeader = true} = props;
if (results && results.length) {
const hasMore = totalCount > results.length;
return (
{showHeader ?
: null}
{results.map(post => )}
{hasMore ? (loading ?
:
) :
}
)
} else if (loading) {
return (
)
} else {
return (
)
}
};
PostsList.displayName = "PostsList";
PostsList.propTypes = {
results: React.PropTypes.array,
terms: React.PropTypes.object,
hasMore: React.PropTypes.bool,
loading: React.PropTypes.bool,
count: React.PropTypes.number,
totalCount: React.PropTypes.number,
loadMore: React.PropTypes.func,
showHeader: React.PropTypes.bool,
};
// const postsListOptions = {
// queryName: 'getPostsList',
// collection: Posts,
// listResolverName: 'postsList',
// totalResolverName: 'postsListTotal',
// fragment: Posts.fragments.list,
// fragmentName: 'fullPostInfo',
// ownPropsVariables: [
// // test note: can't overwrite atm
// // {propName: 'limit', graphqlType: 'Int', defaultValue: 2, usedForTotal: false},
// // note:give the list hoc the ability to catch props coming from upper in the component tree
// {propName: 'terms', graphqlType: 'Terms', usedForTotal: true},
// ],
// };
const fragment = gql`
fragment postsListFragment on Post {
_id
title
url
slug
thumbnailUrl
baseScore
postedAt
sticky
status
categories {
# ...minimumCategoryInfo
_id
name
slug
}
commentCount
commenters {
# ...avatarUserInfo
_id
__displayName
__emailHash
__slug
}
upvoters {
_id
}
downvoters {
_id
}
upvotes # should be asked only for admins?
score # should be asked only for admins?
viewCount # should be asked only for admins?
clickCount # should be asked only for admins?
user {
# ...avatarUserInfo
_id
__displayName
__emailHash
__slug
}
}
`;
const options = {
collection: Posts,
queryName: 'postsListQuery',
fragmentName: 'postsListFragment',
fragment: fragment,
};
Telescope.registerComponent('PostsList', PostsList, withList(options));