diff options
| author | Wes Bos <wesbos@gmail.com> | 2017-09-21 15:39:12 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2017-09-21 15:39:12 -0400 |
| commit | 3b45dd7b593825721ec9ee9f6a49c732601b1ae0 (patch) | |
| tree | a2e8e73d6b6b6bc32eda2bb79af817397e4304f5 /components/Pagination.js | |
| parent | 1450e579c67e3d969cb099dfe6c1cefd1e313fb5 (diff) | |
Cha Ching
Diffstat (limited to 'components/Pagination.js')
| -rw-r--r-- | components/Pagination.js | 70 |
1 files changed, 33 insertions, 37 deletions
diff --git a/components/Pagination.js b/components/Pagination.js index 1b75ed8..fa42e35 100644 --- a/components/Pagination.js +++ b/components/Pagination.js @@ -1,47 +1,43 @@ -import React, { Component } from 'react' -import { graphql, gql, compose } from 'react-apollo' +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 'next/link' +import { Link } from '../routes'; -class Pagination extends Component { - render() { - const { loading, error } = this.props.allItemsQuery; +const Pagination = props => { + const { loading, error } = props.allItemsQuery; - if(loading) return <p>Loading Item...</p> + if (loading) return <p>Loading Item...</p>; - const meta = this.props.allItemsQuery._allItemsMeta; - const { page } = this.props; - const pages = Math.floor(meta.count / 3); - return ( - <div> - <p> - Page <strong>{page} </strong> - of - <strong>{pages} </strong> - - - <strong>{meta.count} </strong> - total - </p> + const meta = props.allItemsQuery._allItemsMeta; + const { page } = props; + const pages = Math.floor(meta.count / 3); + return ( + <div> + <p> + Page <strong>{page} </strong> + of + <strong>{pages} </strong> + - + <strong>{meta.count} </strong> + total + </p> - { page > 1 - ? <Link prefetch href={{ pathname: 'items', query: { page: page - 1 }}}><a>←Prev</a></Link> - : null - } + {page > 1 ? ( + <Link prefetch route="items" params={{ page: page - 1 }}> + <a>←Prev</a> + </Link> + ) : null} - { - page <= pages - ? <Link prefetch href={{ pathname: 'items', query: { page: page + 1 }}}><a>Next →</a></Link> - : null - } + {page <= pages ? ( + <Link prefetch route="items" params={{ page: page + 1 }}> + <a>Next →</a> + </Link> + ) : null} + </div> + ); +}; - </div> - ) - } -} - -const ComponentWithMutations = compose( - graphql(ALL_ITEMS_QUERY, { name: 'allItemsQuery' }) -)(Pagination); +const ComponentWithMutations = compose(graphql(ALL_ITEMS_QUERY, { name: 'allItemsQuery' }))(Pagination); export default ComponentWithMutations; |
