-
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
NguyenHHKiet
committed
Jun 26, 2023
1 parent
ca82cf4
commit 5030ba1
Showing
18 changed files
with
468 additions
and
55 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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,120 @@ | ||
import React, { useState } from "react"; | ||
import { Link, useLoaderData, useSearchParams } from "react-router-dom"; | ||
import Form from "react-bootstrap/Form"; | ||
import InputGroup from "react-bootstrap/InputGroup"; | ||
|
||
import classes from "./Categories.module.scss"; | ||
import ProductItem from "../../ListOfProducts/ProductItem"; | ||
import Row from "react-bootstrap/esm/Row"; | ||
import { useDispatch } from "react-redux"; | ||
|
||
const arrTitle = [ | ||
"APPLE", | ||
"All", | ||
"IPHONE & MAC", | ||
"iPhone", | ||
"iPad", | ||
"Macbook", | ||
"WIRELESS", | ||
"Airpod", | ||
"Watch", | ||
"OTHER", | ||
"Mouse", | ||
"Keyboard", | ||
"Other", | ||
]; | ||
|
||
const Categories = () => { | ||
const data = useLoaderData(); | ||
const [params] = useSearchParams(); | ||
const sortId = params.get("sort"); | ||
|
||
const dispatch = useDispatch(); | ||
const [detail, setDetail] = useState(null); | ||
|
||
if (detail) { | ||
dispatch({ type: "SELECT", payload: detail.info }); | ||
setDetail(null); | ||
} | ||
|
||
let content = data; | ||
if (sortId) { | ||
switch (sortId.toLowerCase()) { | ||
case "all": | ||
content = data; | ||
break; | ||
|
||
default: | ||
content = data.filter( | ||
(item) => item.category === sortId.toLowerCase() | ||
); | ||
break; | ||
} | ||
} | ||
|
||
const Title = (item) => { | ||
let linked; | ||
if ( | ||
item !== "APPLE" && | ||
item !== "IPHONE & MAC" && | ||
item !== "WIRELESS" && | ||
item !== "OTHER" | ||
) { | ||
linked = `?sort=${item}`; | ||
} | ||
return ( | ||
<Link | ||
key={item} | ||
className="px-3 py-2 fst-italic fw-light" | ||
to={linked}> | ||
{item} | ||
</Link> | ||
); | ||
}; | ||
|
||
return ( | ||
<div className={`${classes.showcase} gap-4`}> | ||
<div className=""> | ||
<h3 className="text-uppercase fst-italic mb-3">Categories</h3> | ||
<div className={classes.arrTitle}> | ||
{arrTitle.map((item) => Title(item))} | ||
</div> | ||
</div> | ||
<div> | ||
<div className="d-flex justify-content-between mb-3"> | ||
<InputGroup className={`${classes.input}`}> | ||
<Form.Control | ||
placeholder="Enter Search Here!" | ||
aria-label="Enter Search Here!" | ||
className="py-2" | ||
/> | ||
</InputGroup> | ||
<Form.Select className={classes.select}> | ||
<option>Default sorting</option> | ||
<option value="1">One</option> | ||
<option value="2">Two</option> | ||
<option value="3">Three</option> | ||
</Form.Select> | ||
</div> | ||
<div className={`d-grid gap-4 py-4`}> | ||
<Row> | ||
{content.length > 0 ? ( | ||
content.map((product) => ( | ||
<ProductItem | ||
key={product._id.$oid} | ||
product={product} | ||
setDetail={setDetail} | ||
isLink={true} | ||
/> | ||
)) | ||
) : ( | ||
<p>Not Found Product</p> | ||
)} | ||
</Row> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Categories; |
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 @@ | ||
.showcase { | ||
display: grid; | ||
grid-template-columns: 2.5fr 7.5fr; | ||
height: 100vh; | ||
.arrTitle { | ||
display: flex; | ||
flex-direction: column; | ||
font-size: smaller; | ||
> * { | ||
text-decoration: none; | ||
color: black; | ||
} | ||
> *:hover { | ||
background-color: #f8f8f8; | ||
} | ||
:nth-child(1) { | ||
background-color: black; | ||
color: white; | ||
font-size: medium; | ||
} | ||
:nth-child(3) { | ||
background-color: #e2e4e2; | ||
color: black; | ||
font-size: medium; | ||
font-weight: 400 !important; | ||
} | ||
:nth-child(7) { | ||
background-color: #e2e4e2; | ||
color: black; | ||
font-size: medium; | ||
font-weight: 400 !important; | ||
} | ||
:nth-child(10) { | ||
background-color: #e2e4e2; | ||
color: black; | ||
font-size: medium; | ||
font-weight: 400 !important; | ||
} | ||
} | ||
} | ||
|
||
.input { | ||
max-width: 20rem; | ||
} | ||
|
||
.select { | ||
max-width: 10rem; | ||
} |
Oops, something went wrong.