From 3b45dd7b593825721ec9ee9f6a49c732601b1ae0 Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Thu, 21 Sep 2017 15:39:12 -0400 Subject: Cha Ching --- components/Pagination.js | 82 +++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 43 deletions(-) (limited to 'components/Pagination.js') 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' - -class Pagination extends Component { - render() { - const { loading, error } = this.props.allItemsQuery; - - if(loading) return

Loading Item...

- - const meta = this.props.allItemsQuery._allItemsMeta; - const { page } = this.props; - const pages = Math.floor(meta.count / 3); - return ( -
-

- Page {page} - of - {pages} - - - {meta.count} - total -

- - { page > 1 - ? ←Prev - : null - } - - { - page <= pages - ? Next → - : null - } - -
- ) - } -} - -const ComponentWithMutations = compose( - graphql(ALL_ITEMS_QUERY, { name: 'allItemsQuery' }) -)(Pagination); +import { Link } from '../routes'; + +const Pagination = props => { + const { loading, error } = props.allItemsQuery; + + if (loading) return

Loading Item...

; + + const meta = props.allItemsQuery._allItemsMeta; + const { page } = props; + const pages = Math.floor(meta.count / 3); + return ( +
+

+ Page {page} + of + {pages} + - + {meta.count} + total +

+ + {page > 1 ? ( + + ←Prev + + ) : null} + + {page <= pages ? ( + + Next → + + ) : null} +
+ ); +}; + +const ComponentWithMutations = compose(graphql(ALL_ITEMS_QUERY, { name: 'allItemsQuery' }))(Pagination); export default ComponentWithMutations; -- cgit v1.3