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'; const PaginationStyles = styled.div` text-align: center; display: inline-grid; grid-template-columns: repeat(4, auto); align-items: stretch; justify-content: center; align-content: center; margin: 2rem 0; border: 1px solid ${props => props.theme.lightgrey}; border-radius: 10px; & > * { margin: 0; padding: 15px 30px; border-right: 1px solid ${props => props.theme.lightgrey}; &:last-child { border-right: 0; } } a[aria-disabled='true'] { color: grey; pointer-events: none; } `; const Pagination = props => { if (props.loading) return

Loading...

; const { aggregate } = props.itemsQuery.itemsConnection; const { page } = props; const pages = Math.ceil(aggregate.count / perPage); return ( ←Prev

Page {page} of {pages}

{aggregate.count} Items Total

= pages}> Next →
); }; Pagination.propTypes = { itemsQuery: PropTypes.shape({ itemsConnection: PropTypes.shape({ aggregate: PropTypes.shape({ count: PropTypes.number.isRequired, }), }), }).isRequired, page: PropTypes.number.isRequired, }; export default compose(itemEnhancer)(Pagination); export { Pagination };