Vulcan/packages/nova-base-components/lib/posts/PostsHome.jsx

122 lines
2.7 KiB
React
Raw Normal View History

2016-08-08 11:18:21 +09:00
import Telescope from 'meteor/nova:lib';
2016-06-17 14:44:53 +09:00
import React, { PropTypes, Component } from 'react';
2016-10-25 16:24:03 +09:00
import { ListContainer } from "meteor/utilities:react-list-container";
2016-06-23 11:40:35 +09:00
import Posts from "meteor/nova:posts";
2016-06-10 19:19:32 +09:00
2016-10-25 16:24:03 +09:00
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
2016-06-11 16:36:18 +09:00
2016-10-25 16:24:03 +09:00
const PostsHome = (props, context) => {
const {loading, posts} = props.data;
return loading ?
<Telescope.components.Loading/> :
<Telescope.components.PostsList
results={posts}
hasMore={true}
ready={true}
count={10}
totalCount={20}
loadMore={()=>{console.log("load more")}}
/>;
};
PostsHome.propTypes = {
data: React.PropTypes.shape({
loading: React.PropTypes.bool,
posts: React.PropTypes.array,
}).isRequired,
params: React.PropTypes.object
};
PostsHome.contextTypes = {
currentUser: React.PropTypes.object
};
const PostsHomeWithData = graphql(gql`
2016-10-25 16:24:03 +09:00
query getPosts($view: String, $offset: Int, $limit: Int) {
posts(view: $view, offset: $offset, limit: $limit) {
_id
title
url
slug
htmlBody
thumbnailUrl
baseScore
postedAt
sticky
categories {
_id
name
slug
}
commentCount
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 {
_id
telescope {
displayName
slug
emailHash
}
}
}
2016-06-17 14:44:53 +09:00
}
2016-10-25 16:24:03 +09:00
`, {
options(ownProps) {
return {
variables: {
// get the view from the query params or ask for the 'top' one as a default
view: ownProps.location && ownProps.location.query && ownProps.location.query.view || 'top',
2016-10-25 16:24:03 +09:00
offset: 0,
limit: 10
}
};
},
})(PostsHome);
PostsHome.displayName = "PostsHome";
module.exports = PostsHomeWithData;
// TODO: remove old code
// class PostsHome extends Component {
// getDefaultView() {
// return {view: 'top'}
// }
2016-06-17 14:44:53 +09:00
2016-10-25 16:24:03 +09:00
// render() {
// const params = {...this.getDefaultView(), ...this.props.location.query, listId: "posts.list.main"};
// const {selector, options} = Posts.parameters.get(params);
2016-06-10 19:19:32 +09:00
2016-10-25 16:24:03 +09:00
// return (
// <ListContainer
// collection={Posts}
// publication="posts.list"
// selector={selector}
// options={options}
// terms={params}
// joins={Posts.getJoins()}
// component={Telescope.components.PostsList}
// cacheSubscription={true}
// listId={params.listId}
// limit={Telescope.settings.get("postsPerPage", 10)}
// />
// )
// }
// };