-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: Add gatsby-image dependencies * feat: Query content, render data * chore: Add, initialise tailwindcss * feat: Grid for the index page * feat: Build product pages * feat: Use createResolvers to add formattedPrice field * feat: Product grid design * feat: Product page design
- Loading branch information
Showing
12 changed files
with
2,704 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react' | ||
|
||
import Layout from './src/components/layout' | ||
|
||
import './src/styles/main.css' | ||
|
||
const wrapPageElement = ({ element, props }) => { | ||
return <Layout {...props}>{element}</Layout> | ||
} | ||
|
||
export { wrapPageElement } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const path = require('path') | ||
|
||
exports.createPages = async ({ actions: { createPage }, graphql }) => { | ||
const { data } = await graphql(` | ||
{ | ||
products: allGraphCmsProduct { | ||
nodes { | ||
description { | ||
text | ||
} | ||
formattedPrice | ||
id | ||
name | ||
slug | ||
} | ||
} | ||
} | ||
`) | ||
|
||
data.products.nodes.forEach((product) => { | ||
createPage({ | ||
component: path.resolve(`src/templates/product-page.js`), | ||
context: { | ||
id: product.id, | ||
product, | ||
}, | ||
path: `/products/${product.slug}`, | ||
}) | ||
}) | ||
} | ||
|
||
exports.createResolvers = ({ createResolvers }) => { | ||
const resolvers = { | ||
GraphCMS_Product: { | ||
formattedPrice: { | ||
type: 'String', | ||
resolve: (source) => { | ||
return new Intl.NumberFormat('en-US', { | ||
currency: 'USD', | ||
style: 'currency', | ||
}).format(source.price) | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
createResolvers(resolvers) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { wrapPageElement } from './gatsby-browser' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
plugins: [require('postcss-preset-env'), require('tailwindcss')], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from 'react' | ||
|
||
function Layout({ children }) { | ||
return <div className="max-w-4xl mx-auto px-4 py-8">{children}</div> | ||
} | ||
|
||
export default Layout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React from 'react' | ||
import { graphql, Link } from 'gatsby' | ||
import Img from 'gatsby-image' | ||
|
||
const IndexPage = ({ data: { products } }) => { | ||
return ( | ||
<ul className="gap-6 grid grid-cols-1 max-w-6xl md:grid-cols-3 mx-auto"> | ||
{products.nodes.map((product) => { | ||
const [mainImage] = product.images | ||
|
||
return ( | ||
<li key={product.id} className="bg-white rounded-lg shadow"> | ||
<Link to={`/products/${product.slug}`}> | ||
<div className="flex-1 flex flex-col p-8"> | ||
{mainImage && ( | ||
<Img | ||
fluid={mainImage.localFile.childImageSharp.fluid} | ||
fadeIn={false} | ||
/> | ||
)} | ||
<h2 className="my-4 text-gray-900 text-xl leading-5 font-medium"> | ||
{product.name} | ||
</h2> | ||
<p className="font-semibold text-purple-600"> | ||
{product.formattedPrice} | ||
</p> | ||
</div> | ||
</Link> | ||
</li> | ||
) | ||
})} | ||
</ul> | ||
) | ||
} | ||
|
||
export const query = graphql` | ||
query PageQuery { | ||
products: allGraphCmsProduct { | ||
nodes { | ||
formattedPrice | ||
id | ||
images { | ||
localFile { | ||
childImageSharp { | ||
fluid { | ||
...GatsbyImageSharpFluid | ||
} | ||
} | ||
} | ||
} | ||
name | ||
slug | ||
} | ||
} | ||
} | ||
` | ||
|
||
export default IndexPage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
|
||
body { | ||
@apply bg-gray-100; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from 'react' | ||
import { graphql } from 'gatsby' | ||
import Img from 'gatsby-image' | ||
|
||
const ProductPage = ({ data: { productImages }, pageContext: { product } }) => { | ||
const [mainImage] = productImages.nodes | ||
|
||
return ( | ||
<div className="bg-white flex flex-1 flex-col md:flex-row p-8 rounded-lg shadow"> | ||
<div className="flex flex-1 flex-col"> | ||
<h2 className="my-4 text-gray-900 text-3xl leading-5 font-medium"> | ||
{product.name} | ||
</h2> | ||
<p className="font-semibold text-purple-600 text-lg"> | ||
{product.formattedPrice} | ||
</p> | ||
{product.description && ( | ||
<React.Fragment> | ||
<hr className="my-4" /> | ||
<p className="leading-relaxed md:text-xl text-lg"> | ||
{product.description.text} | ||
</p> | ||
</React.Fragment> | ||
)} | ||
</div> | ||
{mainImage && ( | ||
<div className="w-full md:w-3/5"> | ||
<Img | ||
fluid={mainImage.localFile.childImageSharp.fluid} | ||
fadeIn={false} | ||
/> | ||
</div> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export const query = graphql` | ||
query ProductImageQuery($id: String!) { | ||
productImages: allGraphCmsAsset( | ||
filter: { productImages: { elemMatch: { id: { eq: $id } } } } | ||
) { | ||
nodes { | ||
localFile { | ||
childImageSharp { | ||
fluid { | ||
...GatsbyImageSharpFluid | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
` | ||
|
||
export default ProductPage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
purge: ['./src/components/**/*.js', './src/pages/**/*.js'], | ||
theme: { | ||
extend: {}, | ||
}, | ||
variants: {}, | ||
plugins: [], | ||
} |
Oops, something went wrong.