From 8a5825d52271d712ec7c8348447d433067e13ef2 Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Thu, 13 Sep 2018 14:18:56 -0400 Subject: DONE --- .../FINISHED/frontend/components/Pagination.js | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 stepped-solutions/FINISHED/frontend/components/Pagination.js (limited to 'stepped-solutions/FINISHED/frontend/components/Pagination.js') diff --git a/stepped-solutions/FINISHED/frontend/components/Pagination.js b/stepped-solutions/FINISHED/frontend/components/Pagination.js new file mode 100644 index 0000000..b84af76 --- /dev/null +++ b/stepped-solutions/FINISHED/frontend/components/Pagination.js @@ -0,0 +1,67 @@ +import React from 'react'; +import gql from 'graphql-tag'; +import { Query } from 'react-apollo'; +import Head from 'next/head'; +import Link from 'next/link'; +import PaginationStyles from './styles/PaginationStyles'; +import { perPage } from '../config'; + +const PAGINATION_QUERY = gql` + query PAGINATION_QUERY { + itemsConnection { + aggregate { + count + } + } + } +`; + +const Pagination = props => ( + + {({ data, loading, error }) => { + if (loading) return

Loading...

; + const count = data.itemsConnection.aggregate.count; + const pages = Math.ceil(count / perPage); + const page = props.page; + return ( + + + + Sick Fits! — Page {page} of {pages} + + + + + ← Prev + + +

+ Page {props.page} of + {pages}! +

+

{count} Items Total

+ + = pages}> + Next → + + +
+ ); + }} +
+); + +export default Pagination; +export { PAGINATION_QUERY }; -- cgit v1.3