From 331da87bd53bc1fb79063d142764c75df9f32170 Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Wed, 14 Mar 2018 12:19:54 -0400 Subject: tests --- frontend/components/Pagination.js | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'frontend/components/Pagination.js') diff --git a/frontend/components/Pagination.js b/frontend/components/Pagination.js index dab7084..abc22d0 100644 --- a/frontend/components/Pagination.js +++ b/frontend/components/Pagination.js @@ -2,6 +2,7 @@ import React from 'react'; import { compose } from 'react-apollo'; import styled from 'styled-components'; import Link from 'next/link'; +import PropTypes from 'prop-types'; import { itemEnhancer } from '../enhancers/enhancers'; import { perPage } from '../config'; @@ -30,12 +31,11 @@ const PaginationStyles = styled.div` `; const Pagination = props => { - if (props.loading) return

Loading Item...

; - const { aggregate, pageInfo } = props.itemsQuery.itemsConnection; + if (props.loading) return

Loading...

; + const { aggregate } = props.itemsQuery.itemsConnection; const { page } = props; - const pages = Math.ceil(aggregate.count / perPage); - console.log({ pageInfo }); + return ( { query: { page: page - 1 }, }} > - ←Prev + + ←Prev +

- Page {page} of {pages} + Page {page} of {pages}

{aggregate.count} Items Total @@ -60,12 +62,24 @@ const Pagination = props => { query: { page: page + 1 }, }} > - = pages}>Next → + = pages}> + Next → + ); }; -const ComponentWithMutations = compose(itemEnhancer)(Pagination); +Pagination.propTypes = { + itemsQuery: PropTypes.shape({ + itemsConnection: PropTypes.shape({ + aggregate: PropTypes.shape({ + count: PropTypes.number.isRequired, + }), + }), + }).isRequired, + page: PropTypes.number.isRequired, +}; -export default ComponentWithMutations; +export default compose(itemEnhancer)(Pagination); +export { Pagination }; -- cgit v1.3