Skip to content

Commit e60d3b7

Browse files
committed
✨ Mostrando productos en productDetail
1 parent a22d3f8 commit e60d3b7

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/Components/Card/Card.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ const Card = (data) => {
66

77
const context = useContext(ShoppingCartContext);
88

9+
const showProduct = (productDetail) => {
10+
context.openProductDetails();
11+
context.setProductToShow(productDetail);
12+
}
13+
914
return (
10-
<div className="bg-white cursor-pointer w-56 h-60 rounded-lg" onClick={() => context.openProductDetails()}>
15+
<div className="bg-white cursor-pointer w-56 h-60 rounded-lg" onClick={() => showProduct(data.data)}>
1116
<figure className="relative mb-2 w-full h-4/5">
1217
<span className="absolute bottom-0 left-0 bg-white/60 rounded-lg text-black text-xm m-2 px-3 py-0.5">
1318
{data.data.category.name}

src/Components/ProductDetail/ProductDetail.jsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ShoppingCartContext } from "../../Context/Context";
55

66
const ProductDetail = () => {
77
const context = useContext(ShoppingCartContext);
8+
console.log("PRODUCT TO SHOW", context.productToShow);
89
return (
910
<aside
1011
className={`${
@@ -13,8 +14,31 @@ const ProductDetail = () => {
1314
>
1415
<div className="flex justify-between items-center p-6">
1516
<h2 className="font-medium text-xl"> Detail</h2>
16-
<XMarkIcon className="h-6 w-6 text-black" onClick={context.closeProductDetails}></XMarkIcon>
17+
<div>
18+
<XMarkIcon
19+
className="h-6 w-6 text-black cursor-pointer"
20+
onClick={context.closeProductDetails}
21+
></XMarkIcon>
22+
</div>
1723
</div>
24+
<figure className="px-6">
25+
<img
26+
className="w-full h-full rounded-lg"
27+
src={context.productToShow.images[0]}
28+
alt={context.productToShow.title}
29+
/>
30+
</figure>
31+
<p className="flex flex-col p-6">
32+
<span className="font-medium text-2xl mb-2">
33+
{context.productToShow.price}
34+
</span>
35+
<span className="font-medium text-md">
36+
{context.productToShow.title}
37+
</span>
38+
<span className="font-light text-sm">
39+
{context.productToShow.description}
40+
</span>
41+
</p>
1842
</aside>
1943
);
2044
};

src/Context/Context.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ import { createContext, useState } from "react";
44
export const ShoppingCartContext = createContext();
55

66
export const ShoppingCartProvider = ({ children }) => {
7+
//Shopping cart - Increment quantity
78
const [count, setCount] = useState(0);
8-
const [isProductDetailsOpen, setIsProductDetailsOpen] = useState(false);
99

10+
//Product detail: Open/close
11+
const [isProductDetailsOpen, setIsProductDetailsOpen] = useState(false);
1012
const openProductDetails = () => setIsProductDetailsOpen(true);
1113
const closeProductDetails = () => setIsProductDetailsOpen(false);
1214

15+
//Product detail: show product details
16+
const [productToShow, setProductToShow] = useState({});
1317
return (
1418
<ShoppingCartContext.Provider
1519
value={{
@@ -18,6 +22,8 @@ export const ShoppingCartProvider = ({ children }) => {
1822
openProductDetails,
1923
closeProductDetails,
2024
isProductDetailsOpen,
25+
productToShow,
26+
setProductToShow,
2127
}}
2228
>
2329
{children}

0 commit comments

Comments
 (0)