-
Notifications
You must be signed in to change notification settings - Fork 38
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
Feat/create typography components + nextjs image component #45
base: master
Are you sure you want to change the base?
Changes from 2 commits
1bc8fd3
3640fac
eb31422
1f8986d
02f6729
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 |
---|---|---|
|
@@ -3,12 +3,17 @@ import Link from 'next/link'; | |
import client from '../src/apollo/ApolloClient'; | ||
import AddToCartButton from '../src/components/cart/AddToCartButton'; | ||
import Hero from '../src/components/home/Hero'; | ||
import NextImage from '../src/components/image'; | ||
import { SubHeading, Paragraph } from '../src/components/typography'; | ||
|
||
import { PRODUCTS_QUERY } from '../src/queries'; | ||
|
||
const NewProducts = ({ products }) => { | ||
return ( | ||
<div className="container mt-5"> | ||
<h2 className="text-center mb-5">Products</h2> | ||
<SubHeading className="text-center mb-5"> | ||
Products | ||
</SubHeading> | ||
{products.length ? ( | ||
<div className="mt-2"> | ||
<div className="products-wrapper row"> | ||
|
@@ -19,16 +24,15 @@ const NewProducts = ({ products }) => { | |
{/* @TODO need to get rid of using databseId here. */} | ||
<Link href={`/product/${item.slug}`}> | ||
<a> | ||
<span className="product-link"> | ||
<img | ||
className="product-image" | ||
src={item.image.sourceUrl} | ||
srcSet={item.image.srcSet} | ||
alt={item.name} | ||
/> | ||
<h5 className="product-name">{item.name}</h5> | ||
<p className="product-price">{item.price}</p> | ||
</span> | ||
<NextImage | ||
className="product-image" | ||
src={item.image.sourceUrl} | ||
alt={item.name} | ||
width="240" | ||
height="240" | ||
/> | ||
<h5 className="product-name">{item.name}</h5> | ||
<Paragraph className="product-price">{item.price}</Paragraph> | ||
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. Add optional chaining at all places |
||
</a> | ||
</Link> | ||
<AddToCartButton product={item} /> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { useState, useEffect } from 'react'; | |
import { isUserValidated } from '../src/utils/auth-functions'; | ||
import isEmpty from '../src/validator/isEmpty'; | ||
import Router from 'next/router'; | ||
|
||
import { Paragraph } from '../src/components/typography'; | ||
/** | ||
* MyAccount functional component. | ||
* | ||
|
@@ -50,7 +50,9 @@ const MyAccount = () => { | |
<div id="dashboard"> | ||
{userData.user.nicename ? <h6>Howdy {userData.user.nicename}!</h6> : ''} | ||
<h5 className="mt-3">Account Details</h5> | ||
{userData.user.email ? <p>Email: {userData.user.email}</p> : ''} | ||
{userData.user.email ? | ||
<Paragraph>Email: {userData.user.email}</Paragraph> : '' | ||
} | ||
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. Use null instead of empty string |
||
</div> | ||
</div> | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { useState } from 'react'; | ||
import { updateCart } from '../../../utils/cart-functions'; | ||
import NextImage from '../../image'; | ||
|
||
const CartItem = ({ item, handleRemoveProductClick, setCart }) => { | ||
const [productCount, setProductCount] = useState(item.qty); | ||
|
@@ -40,11 +41,12 @@ const CartItem = ({ item, handleRemoveProductClick, setCart }) => { | |
</span> | ||
</th> | ||
<td className="wd-cart-element"> | ||
<img | ||
width="64" | ||
<NextImage | ||
src={item.image.sourceUrl} | ||
srcSet={item.image.srcSet} | ||
alt={item.image.title} | ||
width="64" | ||
height="64" | ||
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. please add sizes attribute, else srcSet won't work |
||
/> | ||
</td> | ||
<td className="wd-cart-element">{item.name}</td> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,61 @@ | ||
import Link from 'next/link'; | ||
import NextImage from '../../src/components/image'; | ||
import { SubHeading } from '../typography'; | ||
|
||
const Categories = () => { | ||
return ( | ||
<div className="container"> | ||
<h2 className="text-center mb-4">Shop by Category</h2> | ||
<SubHeading className="text-center mb-4">Shop by Category</SubHeading> | ||
<div className="woocommerce"> | ||
<ul className="products row mx-auto"> | ||
<li className="product-category product first col-md-4"> | ||
<Link as={`/`} href={`/`}> | ||
<a className=""> | ||
<img | ||
<NextImage | ||
src="https://woo-vsf.dev5.rt.gw/wp-content/uploads/2019/05/accessories.jpg" | ||
alt="Accessories" | ||
width="324" | ||
height="324" | ||
srcSet="https://woo-vsf.dev5.rt.gw/wp-content/uploads/2019/05/accessories.jpg 801w, https://woo-vsf.dev5.rt.gw/wp-content/uploads/2019/05/accessories-150x150.jpg 150w, https://woo-vsf.dev5.rt.gw/wp-content/uploads/2019/05/accessories-300x300.jpg 300w, https://woo-vsf.dev5.rt.gw/wp-content/uploads/2019/05/accessories-768x768.jpg 768w" | ||
sizes="(max-width: 324px) 100vw, 324px" | ||
/> | ||
<h2 className="woocommerce-loop-category__title"> | ||
<SubHeading className="woocommerce-loop-category__title"> | ||
Accessories <mark className="count">(4)</mark> | ||
</h2> | ||
</SubHeading> | ||
</a> | ||
</Link> | ||
</li> | ||
<li className="product-category product col-md-4"> | ||
<Link as={`/`} href={`/`}> | ||
<a className=""> | ||
<img | ||
<NextImage | ||
src="https://woo-vsf.dev5.rt.gw/wp-content/uploads/2019/05/hoodies.jpg" | ||
alt="Hoodies" | ||
width="324" | ||
height="324" | ||
srcSet="https://woo-vsf.dev5.rt.gw/wp-content/uploads/2019/05/hoodies.jpg 800w, https://woo-vsf.dev5.rt.gw/wp-content/uploads/2019/05/hoodies-150x150.jpg 150w, https://woo-vsf.dev5.rt.gw/wp-content/uploads/2019/05/hoodies-300x300.jpg 300w, https://woo-vsf.dev5.rt.gw/wp-content/uploads/2019/05/hoodies-768x768.jpg 768w" | ||
sizes="(max-width: 324px) 100vw, 324px" | ||
/> | ||
<h2 className="woocommerce-loop-category__title"> | ||
<SubHeading className="woocommerce-loop-category__title"> | ||
Hoodies <mark className="count">(4)</mark> | ||
</h2> | ||
</SubHeading> | ||
</a> | ||
</Link> | ||
</li> | ||
<li className="product-category product last col-md-4"> | ||
<Link as={`/`} href={`/`}> | ||
<a className=""> | ||
<img | ||
<NextImage | ||
src="https://woo-vsf.dev5.rt.gw/wp-content/uploads/2019/05/tshirts.jpg" | ||
alt="Tshirts" | ||
width="324" | ||
height="324" | ||
srcSet="https://woo-vsf.dev5.rt.gw/wp-content/uploads/2019/05/tshirts.jpg 801w, https://woo-vsf.dev5.rt.gw/wp-content/uploads/2019/05/tshirts-150x150.jpg 150w, https://woo-vsf.dev5.rt.gw/wp-content/uploads/2019/05/tshirts-300x300.jpg 300w, https://woo-vsf.dev5.rt.gw/wp-content/uploads/2019/05/tshirts-768x768.jpg 768w" | ||
sizes="(max-width: 324px) 100vw, 324px" | ||
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. Lets not keep this hardcoded |
||
/> | ||
<h2 className="woocommerce-loop-category__title"> | ||
<SubHeading className="woocommerce-loop-category__title"> | ||
Tshirts <mark className="count">(4)</mark> | ||
</h2> | ||
</SubHeading> | ||
</a> | ||
</Link> | ||
</li> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const defaultImg = | ||
"default image link"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Image from 'next/image' | ||
import { defaultImg } from './defaultImg'; | ||
|
||
const NextImage = (props) => { | ||
|
||
const { | ||
className, | ||
src, | ||
srcSet, | ||
alt, | ||
width, | ||
height, | ||
sizes | ||
} = props; | ||
const imgSrc = typeof src === 'string' ? src || defaultImg : defaultImg; | ||
|
||
return ( | ||
<Image | ||
className={className} | ||
src={imgSrc} | ||
alt={alt} | ||
width={width} | ||
height={height} | ||
sizes={sizes} | ||
/> | ||
); | ||
} | ||
|
||
export default NextImage; |
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.
Change to item?.image?.sourceUrl