diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-02-02 15:23:20 -0500 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-02-02 15:23:20 -0500 |
| commit | eabff7cd396d1f37ceb929e666f082ce57f07919 (patch) | |
| tree | 6fbd487688ee9e53bada734288994c35b732150e /frontend/components/Pagination.js | |
| parent | cd0b07b3adb36fb5ec098f9e511ab45d774fee7b (diff) | |
updateS
Diffstat (limited to 'frontend/components/Pagination.js')
| -rw-r--r-- | frontend/components/Pagination.js | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/frontend/components/Pagination.js b/frontend/components/Pagination.js index dedd231..28785be 100644 --- a/frontend/components/Pagination.js +++ b/frontend/components/Pagination.js @@ -1,17 +1,19 @@ -import React, { Component } from 'react'; -import { graphql, gql, compose } from 'react-apollo'; -import { ALL_ITEMS_QUERY } from '../queries'; -import withData from '../lib/withData'; -import { Link } from '../routes'; +import React, { Component } from "react"; +import { graphql, gql, compose } from "react-apollo"; +import { ALL_ITEMS_QUERY } from "../queries"; +import withData from "../lib/withData"; +import { Link } from "../routes"; +import { itemEnhancer } from "../enhancers/enhancers"; const Pagination = props => { const { loading, error } = props.allItemsQuery; if (loading) return <p>Loading Item...</p>; - const meta = props.allItemsQuery._allItemsMeta; + const { aggregate, pageInfo } = props.allItemsQuery.itemsConnection; + const { page } = props; - const pages = Math.floor(meta.count / 3); + const pages = Math.floor(aggregate.count / 3); return ( <div> <p> @@ -19,17 +21,16 @@ const Pagination = props => { of <strong>{pages} </strong> - - <strong>{meta.count} </strong> + <strong>{aggregate.count} </strong> total </p> - - {page > 1 ? ( + {pageInfo.hasPreviousPage ? ( <Link prefetch route="items" params={{ page: page - 1 }}> <a>←Prev</a> </Link> ) : null} - {page < pages ? ( + {pageInfo.hasNextPage ? ( <Link prefetch route="items" params={{ page: page + 1 }}> <a>Next →</a> </Link> @@ -38,6 +39,6 @@ const Pagination = props => { ); }; -const ComponentWithMutations = compose(graphql(ALL_ITEMS_QUERY, { name: 'allItemsQuery' }))(Pagination); +const ComponentWithMutations = compose(itemEnhancer)(Pagination); export default ComponentWithMutations; |
