-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from include-davis/feat/products-page
Feat/products page
- Loading branch information
Showing
14 changed files
with
119 additions
and
2 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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[ | ||
{ | ||
"name": "shop", | ||
"slug": "/shop" | ||
"slug": "/products" | ||
}, | ||
{ | ||
"name": "about", | ||
|
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,26 @@ | ||
'use client'; | ||
import { useEffect, useState } from 'react'; | ||
import products from '../products/_data/products'; | ||
|
||
interface Product { | ||
id: string; | ||
src: string; | ||
alt: string; | ||
name: string; | ||
price: number; | ||
} | ||
|
||
export default function useProduct(id: string) { | ||
const [product, setProduct] = useState<Product | null>(null); | ||
const [loading, setLoading] = useState(true); | ||
|
||
useEffect(() => { | ||
const filteredProducts = products.filter((p) => p.id === id); | ||
if (filteredProducts.length !== 0) { | ||
setProduct(filteredProducts[0]); | ||
} | ||
setLoading(false); | ||
}, [id]); | ||
|
||
return { product, loading }; | ||
} |
Empty file.
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,23 @@ | ||
'use client'; | ||
import useProduct from '@hooks/useProduct'; | ||
import ProductPage from '../_components/ProductPage/ProductPage'; | ||
|
||
interface Product { | ||
id: string; | ||
src: string; | ||
alt: string; | ||
name: string; | ||
price: number; | ||
} | ||
|
||
export default function Product({ params }: { params: { id: string } }) { | ||
const { product, loading } = useProduct(params.id); | ||
if (loading) { | ||
return 'loading...'; | ||
} | ||
|
||
if (product === null) { | ||
return 'product does not exist'; | ||
} | ||
return <ProductPage {...(product as Product)} />; | ||
} |
25 changes: 25 additions & 0 deletions
25
app/(pages)/product/_components/ProductPage/ProductPage.module.scss
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,25 @@ | ||
$mid-gap: var(--spacer); | ||
|
||
.container { | ||
display: flex; | ||
flex-direction: row; | ||
padding: var(--medium-spacer); | ||
gap: $mid-gap; | ||
background-color: var(--light-foreground); | ||
} | ||
|
||
.main_img_container { | ||
width: calc(calc(100% - $mid-gap) / 2); | ||
aspect-ratio: calc(5/4); | ||
position: relative; | ||
|
||
.main_image { | ||
object-fit: cover; | ||
} | ||
} | ||
|
||
.prod_information { | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--spacer); | ||
} |
25 changes: 25 additions & 0 deletions
25
app/(pages)/product/_components/ProductPage/ProductPage.tsx
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,25 @@ | ||
import styles from './ProductPage.module.scss'; | ||
import Image from 'next/image'; | ||
|
||
interface Product { | ||
id: string; | ||
src: string; | ||
alt: string; | ||
name: string; | ||
price: number; | ||
} | ||
|
||
export default function ProductPage({ id: _, src, alt, name, price }: Product) { | ||
return ( | ||
<div className={styles.container}> | ||
<div className={styles.main_img_container}> | ||
<Image src={src} alt={alt} fill className={styles.main_image} /> | ||
</div> | ||
<div className={styles.prod_information}> | ||
<h2>{name}</h2> | ||
<p>${price}</p> | ||
<button className={styles.add_to_cart_button}>add to cart</button> | ||
</div> | ||
</div> | ||
); | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.