/
TaxonomyPostsData.js
51 lines (50 loc) · 1.51 KB
/
TaxonomyPostsData.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { graphql } from "@apollo/react-hoc";
import { SEARCH_POSTS_BY_TAXONOMY } from "../queries/Queries";
import config from "../../config";
export default graphql(SEARCH_POSTS_BY_TAXONOMY, {
options: props => {
let offset =
props.router.match.params.page_no == 1
? 0
: props.router.match.params.page_no;
let type = "";
if (props.type === "category") {
type = "post_category";
} else if (props.type === "tag") {
type = "post_tag";
}
return {
variables: {
type,
slug: props.query || props.router.match.params.query,
postType: "post",
limit: props.limit || config.itemsPerPage,
offset: parseInt(props.offset || offset || 0),
},
};
},
props: ({ data: { loading, postsByTaxSlug, fetchMore } }) => {
return {
posts: (postsByTaxSlug && postsByTaxSlug.posts) || [],
total: (postsByTaxSlug && postsByTaxSlug.count) || 0,
loading,
fetchMore: variables => {
return fetchMore({
variables: variables,
updateQuery: (previousResult, { fetchMoreResult }) => {
return {
postsByTaxSlug: {
count: fetchMoreResult.postsByTaxSlug.count,
posts: [
...previousResult.postsByTaxSlug.posts,
...fetchMoreResult.postsByTaxSlug.posts,
],
__typename: previousResult.postsByTaxSlug.__typename,
},
};
},
});
},
};
},
});