-
Notifications
You must be signed in to change notification settings - Fork 154
Add product gallery + basic CSS styling #246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 = { | ||
| 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} /> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we using placeholder? The project has images with each product.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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} /> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
|
@@ -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> | ||
|
|
||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.