Skip to content
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

Faster store #39

Open
wants to merge 28 commits into
base: faster-contentful-main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d30f2e3
adds linked in link in footer
mxayon Oct 18, 2022
2fa3608
fix header links text
mxayon Oct 19, 2022
87ee2e6
icon fix
mxayon Oct 19, 2022
0603d41
calls products with graphql query
mxayon Nov 3, 2022
1a65282
installs styled-components
mxayon Nov 7, 2022
4befbe8
creates new product card component, accepts product as prop
mxayon Nov 9, 2022
d9e6d63
calls producst with graphQL query and adds to product card
mxayon Nov 9, 2022
bf2727f
creates template for product pages
mxayon Nov 9, 2022
c42deea
queries all products and creates unique page with handle field
mxayon Nov 9, 2022
69d1f0f
queries all products and creates unique page with handle field
mxayon Nov 9, 2022
9b3a44d
Merge branch 'faster-contentful-main' into faster-store
mxayon Nov 16, 2022
a713101
fix exports
cjdeleon62 Nov 16, 2022
306e7e8
pulls in new changes to about from main
mxayon Nov 21, 2022
c7ffd86
creates product card component, accepts product as prop
mxayon Nov 21, 2022
2966b3e
creates template for each product page, displays title and description
mxayon Nov 21, 2022
e9940f6
creates styled product show page
mxayon Nov 21, 2022
a40af77
installs isopromorphic-fetch, shopify-buy plugins and creates store c…
mxayon Nov 21, 2022
998469a
creates default values for checkout, store provider for checkout process
mxayon Nov 22, 2022
0bc9225
adds CombinedProvider to access across shop
mxayon Nov 22, 2022
5ef4fda
creates primary button for adding to cart
mxayon Nov 22, 2022
5d11e10
creates product row for cart page
mxayon Nov 22, 2022
53c50a7
codes cart page and appends layout to products page
mxayon Nov 29, 2022
6db2fd1
implements add to cart functionality
mxayon Nov 30, 2022
455b474
add to cart functionality for product page
mxayon Nov 30, 2022
e4ceee9
integrates the addVariantToCart function to onClick event of Primary …
mxayon Nov 30, 2022
0decd56
removes floating ;
mxayon Dec 1, 2022
d885d08
removes 0 hard coded by price
mxayon Dec 1, 2022
9d9a79e
fix layout casing in import statement
mxayon Dec 1, 2022
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
3 changes: 3 additions & 0 deletions gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
import '@fontsource/montserrat';
import '@fontsource/montserrat/700.css';
import CombinedProvider from './src/context/CombinedProvider';

export const wrapRootElement = CombinedProvider;
7 changes: 7 additions & 0 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ module.exports = {
environment: process.env.CONTENTFUL_ENV,
},
},
{
resolve: 'gatsby-source-shopify',
options: {
storeUrl: process.env.SHOPIFY_STORE_NAME,
password: process.env.SHOPIFY_ADMIN_ACCESS_TOKEN,
},
},
'gatsby-plugin-postcss',
'gatsby-plugin-sass',
'gatsby-plugin-image',
Expand Down
34 changes: 34 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fetch = require('node-fetch');
const path = require('path');

// Create source nodes
exports.sourceNodes = async ({
Expand Down Expand Up @@ -93,6 +94,26 @@ exports.createPages = async ({ actions, graphql }) => {
}
}
}
allShopifyProduct {
edges {
node {
title
handle
variants {
shopifyId
image {
src
}
}
priceRangeV2 {
maxVariantPrice {
amount
}
}
description
}
}
}
}
`);

Expand All @@ -117,6 +138,7 @@ exports.createPages = async ({ actions, graphql }) => {

data.allContentfulHomePage.edges.forEach((edge) => {
const { slug } = edge.node;
console.log('here is the slug', slug);
actions.createPage({
path: slug,
context: {
Expand Down Expand Up @@ -169,4 +191,16 @@ exports.createPages = async ({ actions, graphql }) => {
component: require.resolve('./src/templates/pokemon.js'),
});
});

// Iterate over all products and create a new page using a template
// The product "handle" is generated automatically by Shopify
data.allShopifyProduct.edges.forEach(({ node }) => {
actions.createPage({
path: `/products/${node.handle}`,
component: path.resolve(`./src/templates/product.js`),
context: {
product: node,
},
});
});
};
2 changes: 2 additions & 0 deletions gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import CombinedProvider from './src/context/CombinedProvider';
export const wrapRootElement = CombinedProvider;
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@
"gatsby-plugin-sharp": "^4.9.1",
"gatsby-source-contentful": "^7.7.2",
"gatsby-source-filesystem": "^4.9.1",
"gatsby-source-shopify": "^7.13.0",
"gatsby-transformer-sharp": "^4.9.0",
"husky": "^8.0.1",
"isomorphic-fetch": "^3.0.0",
"node-fetch": "^2.6.7",
"postcss": "^8.4.12",
"prop-types": "^15.8.1",
Expand All @@ -53,6 +55,8 @@
"react-dom": "^17.0.1",
"react-helmet": "^6.1.0",
"sass": "^1.49.9",
"shopify-buy": "^2.17.1",
"styled-components": "^5.3.6",
"tailwindcss": "^3.0.23",
"yup": "^0.32.11"
},
Expand Down
42 changes: 42 additions & 0 deletions src/components/PrimaryButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-disable react/prop-types */
import React from 'react';
import styled from 'styled-components';

const PrimaryButton = ({ text, onClick, disabled = false }) => {
return (
<ButtonWrapper onClick={onClick} disabled={disabled}>
<Title>{text}</Title>
</ButtonWrapper>
);
};

export default PrimaryButton;

const ButtonWrapper = styled.button`
background: #014c40;
border: none;
border-radius: 30px;
height: 40px;
width: fit-content;
display: flex;
justify-content: center;
align-items: center;
padding: 0 20px;
cursor: pointer;
:hover {
transform: scale(1.2);
transition: 0.2s;
}
:disabled {
background: rgba(1, 76, 64, 0.5);
transform: none;
cursor: not-allowed;
}
`;

const Title = styled.p`
margin: 0;
font-weight: 600;
font-size: 12px;
color: #ffffff;
`;
100 changes: 100 additions & 0 deletions src/components/ProductCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/* eslint-disable react/prop-types */
import React from 'react';
import styled from 'styled-components';
import { navigate } from 'gatsby-link';
import useStore from '../context/StoreContext';

const ProductCard = ({ product }) => {
const { addVariantToCart } = useStore();
return (
<Wrapper>
<AddButton onClick={() => addVariantToCart(product, 1)}>
<p>+</p>
</AddButton>
<ContentWrapper onClick={() => navigate(`${product.handle}`)}>
<Image src={product.variants[0].image.src} />
<TextWrapper>
<Title>{product.title}</Title>
<Price>
{product.priceRangeV2.maxVariantPrice.amount}$
</Price>
</TextWrapper>
</ContentWrapper>
</Wrapper>
);
};

export default ProductCard;

const Wrapper = styled.div`
display: grid;
justify-content: center;
align-items: center;
width: 200px;
border-radius: 20px;

gap: 10px;
cursor: pointer;
position: relative;
box-shadow: 0px 20px 40px rgba(52, 53, 99, 0.2),
0px 1px 3px rgba(0, 0, 0, 0.05);
`;

const ContentWrapper = styled.div``;

const Image = styled.img`
width: 200px;
height: 300px;
object-fit: cover;
border-radius: 20px;
margin: 0;
`;

const TextWrapper = styled.div`
position: absolute;
bottom: 0px;
left: 0px;
border-radius: 0 0 20px 20px;
background: rgba(255, 255, 255, 0.2);
width: 200px;
padding: 10px 0;
backdrop-filter: blur(40px);
`;

const Title = styled.p`
font-weight: 600;
text-align: center;
margin: 0;
color: #014c40;
`;

const Price = styled.p`
font-weight: normal;
text-align: center;
margin: 0;
`;

const AddButton = styled.div`
position: absolute;
top: 20px;
right: 20px;
background: #014c40;
padding: 10px;
width: 40px;
height: 40px;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;

:hover {
transform: scale(1.2);
transition: 0.2s;
}

p {
margin: 0;
color: white;
font-weight: bold;
}
`;
56 changes: 56 additions & 0 deletions src/components/ProductRow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* eslint-disable react/prop-types */
import React from 'react';
import styled from 'styled-components';

const ProductRow = ({ item }) => {
const { product, quantity } = item;

return (
<Wrapper>
<ProductWrapper>
<Image src={product.images[0]?.src} alt={product.title} />
<Subtitle>{product.title}</Subtitle>
</ProductWrapper>
<Subtitle>{quantity}</Subtitle>
<DeleteButton onClick={() => console.log('Remove item')}>
Remove
</DeleteButton>
</Wrapper>
);
};

export default ProductRow;

const Wrapper = styled.div`
display: grid;
grid-template-columns: repeat(3, 330px);
gap: 20px;
align-items: center;
width: 330px;
`;

const ProductWrapper = styled.div`
display: grid;
grid-template-columns: 80px auto;
gap: 20px;
align-items: center;
width: 330px;
`;

const Image = styled.img`
width: 80px;
height: 80px;
object-fit: cover;
border-radius: 20px;
`;

const Subtitle = styled.p`
font-weight: bold;
font-size: 14px;
`;

const DeleteButton = styled.p`
color: #a61b2b;
font-size: 14px;
cursor: pointer;
`;
10 changes: 10 additions & 0 deletions src/context/CombinedProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable react/prop-types */
import React from 'react';

import { StoreProvider } from './StoreContext';

const CombinedProvider = ({ element }) => {
return <StoreProvider>{element}</StoreProvider>;
};

export default CombinedProvider;
Loading