Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions using-pagination/src/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
import Link from 'next/link';
import { gql } from 'graphql-request';

import { graphcms } from '../../lib/_graphcms';

const limit = 1;

const singleProductStyle = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to improve styling for all our examples. I'm happy if you want to add these here, but FYI, these may get removed with an updated design when we get some design resources to help here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's definitely a thing! Do you already have basic styling from other example that I could use here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these may get removed with an updated design when we get some design resources to help here

display: 'flex',
flexDirection: 'column',
width: '300px',
margin: '10px',
};

function SingleProduct({product, index}) {
return (
<div style={singleProductStyle}>
<img src={`https://via.placeholder.com/300x200?text=${product.name}`} width={300} height={200} alt={product.name} title={product.name} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using placeholder? The project has images with each product.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code didn't have images in it, so I didn't know. 😅 Could you please invite me to the project?

<Link href={`/products/${index+1}`}>
<a>{product.name}</a>
</Link>
</div>
)
}

const productListStyle = {
display: 'flex'
};

function IndexPage({ products }) {
return products.map(({ node: product }) => (
<pre>{JSON.stringify(product, 2, null)}</pre>
));
return (
<div style={productListStyle}>
{products.map(({ node: product }, index) => {
return <SingleProduct key={product.id} product={product} index={index} />
})}
</div>
);
}

export async function getStaticProps() {
Expand Down
36 changes: 33 additions & 3 deletions using-pagination/src/pages/products/[page].js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@ import { graphcms } from '../../../lib/_graphcms';

const limit = 1;

const singleProductStyle = {
display: 'flex',
flexDirection: 'column',
width: '300px',
margin: '10px',
color: '#000',
};

function SingleProduct({product}) {
return (
<div style={singleProductStyle} key={product.id}>
<img src={`https://via.placeholder.com/300x200?text=${product.name}`} width={300} height={200} alt={product.name} title={product.name} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again. Products have images. You can query these 😃

<h3>{product.name}</h3>
</div>
)
}

const navStyle = {
display: 'inline-block',
backgroundColor: '#ccc',
color: '#111',
textDecoration: 'none',
padding: '2px 6px',
marginRight: '5px',
}

function ProductPage({
currentPageNumber,
hasNextPage,
Expand All @@ -13,15 +39,19 @@ function ProductPage({
}) {
return (
<React.Fragment>
<pre>{JSON.stringify(products, 2, null)}</pre>
<Link href={'/'}>
<a>Home</a>
</Link>
<p>Page {currentPageNumber}</p>
<SingleProduct product={products[0].node} />
{hasPreviousPage ? (
<Link href={`/products/${currentPageNumber - 1}`}>
<a>Previous page</a>
<a style={navStyle}>Previous page</a>
</Link>
) : null}
{hasNextPage ? (
<Link href={`/products/${currentPageNumber + 1}`}>
<a>Next page</a>
<a style={navStyle}>Next page</a>
</Link>
) : null}
</React.Fragment>
Expand Down