-
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.
- Loading branch information
Amir Amiri
committed
Feb 25, 2023
1 parent
aef5010
commit 7302ce4
Showing
16 changed files
with
419 additions
and
100 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
22 changes: 22 additions & 0 deletions
22
src/components/category-preview/category-preview.component.jsx
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,22 @@ | ||
import { Link } from 'react-router-dom'; | ||
import ProductCard from '../product-card/product-card.component'; | ||
import './category-preview.styles.scss'; | ||
|
||
const CategoryPreview = ({ title, products }) => { | ||
return ( | ||
<div className='category-preview-container'> | ||
<h2> | ||
<Link className='title' to={title}>{title.toUpperCase()}</Link> | ||
</h2> | ||
<div className='preview'> | ||
{ | ||
products | ||
.filter((_, idx) => idx < 4) | ||
.map((product) => <ProductCard key={product.id} product={product} />) | ||
} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default CategoryPreview; |
18 changes: 18 additions & 0 deletions
18
src/components/category-preview/category-preview.styles.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,18 @@ | ||
.category-preview-container { | ||
display: flex; | ||
flex-direction: column; | ||
margin-bottom: 30px; | ||
|
||
.title { | ||
font-size: 28px; | ||
margin-bottom: 25px; | ||
cursor: pointer; | ||
} | ||
|
||
.preview { | ||
display: grid; | ||
grid-template-columns: repeat(4, 1fr); | ||
column-gap: 20px; | ||
} | ||
} | ||
|
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
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 @@ | ||
import { useEffect } from "react"; | ||
import { createContext, useState } from "react"; | ||
import { GetCategoriesAndDocuments } from "../utils/firebase/firebase.utils"; | ||
|
||
|
||
export const CategoriesContext = createContext({ | ||
categoriesMap: [], | ||
}); | ||
|
||
export const CategoriesProvider = ({ children }) => { | ||
const [categoriesMap, setCategoriesMap] = useState({}); | ||
useEffect(() => { | ||
const getCategoriesMap = async () => { | ||
const categoriesMap = await GetCategoriesAndDocuments(); | ||
setCategoriesMap(categoriesMap) | ||
} | ||
|
||
getCategoriesMap(); | ||
}, []) | ||
const value = { categoriesMap }; | ||
return ( | ||
<CategoriesContext.Provider value={value}> | ||
{children} | ||
</CategoriesContext.Provider> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
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
22 changes: 22 additions & 0 deletions
22
src/routes/categories-preview/categories-preview.component.jsx
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,22 @@ | ||
import { useContext, Fragment } from "react"; | ||
import { CategoriesContext } from "../../contexts/categories.context"; | ||
import CategoryPreview from "../../components/category-preview/category-preview.component"; | ||
|
||
const CategoriesPreview = () => { | ||
const { categoriesMap } = useContext(CategoriesContext); | ||
|
||
return ( | ||
<Fragment> | ||
{ | ||
Object.keys(categoriesMap).map(title => { | ||
const products = categoriesMap[title]; | ||
return <CategoryPreview key={title} title={title} products={products} /> | ||
}) | ||
} | ||
|
||
</Fragment> | ||
) | ||
|
||
} | ||
|
||
export default CategoriesPreview; |
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,31 @@ | ||
import { Fragment, useContext, useEffect, useState } from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
import { CategoriesContext } from '../../contexts/categories.context'; | ||
import ProductCard from '../../components/product-card/product-card.component'; | ||
import './category.styles.scss'; | ||
|
||
const Category = () => { | ||
const { category } = useParams() | ||
const { categoriesMap } = useContext(CategoriesContext) | ||
const [products, setProducts] = useState(categoriesMap[category]) | ||
|
||
useEffect(() => { | ||
setProducts(categoriesMap[category]) | ||
}, [categoriesMap, category]) | ||
|
||
return ( | ||
<Fragment> | ||
<h2 className='category-title'> | ||
{category} | ||
</h2> | ||
<div className='category-container'> | ||
{products && | ||
products.map((product) => <ProductCard key={product.id} product={product} />) | ||
} | ||
</div> | ||
</Fragment> | ||
|
||
) | ||
} | ||
|
||
export default Category; |
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,13 @@ | ||
.category-container { | ||
display: grid; | ||
grid-template-columns: repeat(4, 1fr); | ||
column-gap: 20px; | ||
row-gap: 50px; | ||
|
||
} | ||
|
||
.category-title { | ||
font-size: 38px; | ||
margin-bottom: 25px; | ||
text-align: center; | ||
} |
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
Oops, something went wrong.