2016-11-10 15:39:04 +09:00
|
|
|
import Telescope from 'meteor/nova:lib';
|
|
|
|
import React, { PropTypes, Component } from 'react';
|
|
|
|
import Posts from "meteor/nova:posts";
|
|
|
|
import { graphql } from 'react-apollo';
|
|
|
|
import gql from 'graphql-tag';
|
|
|
|
|
2016-11-11 18:19:18 +09:00
|
|
|
export default function withPostsList (params) {
|
2016-11-10 15:39:04 +09:00
|
|
|
return graphql(gql`
|
|
|
|
query getPostsView($terms: Terms, $offset: Int, $limit: Int) {
|
|
|
|
postsViewTotal(terms: $terms)
|
|
|
|
posts(terms: $terms, offset: $offset, limit: $limit) {
|
|
|
|
${Posts.graphQLQueries.list}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, {
|
|
|
|
options(ownProps) {
|
|
|
|
return {
|
|
|
|
variables: {
|
2016-11-11 18:19:18 +09:00
|
|
|
terms: ownProps.terms,
|
2016-11-10 15:39:04 +09:00
|
|
|
offset: 0,
|
|
|
|
limit: 10
|
|
|
|
},
|
|
|
|
// pollInterval: 20000,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
props(props) {
|
|
|
|
|
|
|
|
const {data: {loading, posts, postsViewTotal, fetchMore}} = props;
|
|
|
|
|
|
|
|
return {
|
|
|
|
loading,
|
|
|
|
results: posts,
|
|
|
|
totalCount: postsViewTotal,
|
|
|
|
count: posts && posts.length,
|
|
|
|
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]};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
...props.ownProps // pass on the props down to the wrapped component
|
|
|
|
};
|
|
|
|
},
|
2016-11-11 16:42:19 +09:00
|
|
|
});
|
2016-11-10 15:39:04 +09:00
|
|
|
}
|