From cd0b07b3adb36fb5ec098f9e511ab45d774fee7b Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Tue, 30 Jan 2018 12:41:01 -0500 Subject: Move to Prisma Backend --- frontend/components/Pagination.js | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 frontend/components/Pagination.js (limited to 'frontend/components/Pagination.js') diff --git a/frontend/components/Pagination.js b/frontend/components/Pagination.js new file mode 100644 index 0000000..dedd231 --- /dev/null +++ b/frontend/components/Pagination.js @@ -0,0 +1,43 @@ +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 '../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