File tree Expand file tree Collapse file tree 3 files changed +38
-3
lines changed Expand file tree Collapse file tree 3 files changed +38
-3
lines changed Original file line number Diff line number Diff line change @@ -6,8 +6,13 @@ const Card = (data) => {
6
6
7
7
const context = useContext ( ShoppingCartContext ) ;
8
8
9
+ const showProduct = ( productDetail ) => {
10
+ context . openProductDetails ( ) ;
11
+ context . setProductToShow ( productDetail ) ;
12
+ }
13
+
9
14
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 ) } >
11
16
< figure className = "relative mb-2 w-full h-4/5" >
12
17
< span className = "absolute bottom-0 left-0 bg-white/60 rounded-lg text-black text-xm m-2 px-3 py-0.5" >
13
18
{ data . data . category . name }
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { ShoppingCartContext } from "../../Context/Context";
5
5
6
6
const ProductDetail = ( ) => {
7
7
const context = useContext ( ShoppingCartContext ) ;
8
+ console . log ( "PRODUCT TO SHOW" , context . productToShow ) ;
8
9
return (
9
10
< aside
10
11
className = { `${
@@ -13,8 +14,31 @@ const ProductDetail = () => {
13
14
>
14
15
< div className = "flex justify-between items-center p-6" >
15
16
< 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 >
17
23
</ 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 >
18
42
</ aside >
19
43
) ;
20
44
} ;
Original file line number Diff line number Diff line change @@ -4,12 +4,16 @@ import { createContext, useState } from "react";
4
4
export const ShoppingCartContext = createContext ( ) ;
5
5
6
6
export const ShoppingCartProvider = ( { children } ) => {
7
+ //Shopping cart - Increment quantity
7
8
const [ count , setCount ] = useState ( 0 ) ;
8
- const [ isProductDetailsOpen , setIsProductDetailsOpen ] = useState ( false ) ;
9
9
10
+ //Product detail: Open/close
11
+ const [ isProductDetailsOpen , setIsProductDetailsOpen ] = useState ( false ) ;
10
12
const openProductDetails = ( ) => setIsProductDetailsOpen ( true ) ;
11
13
const closeProductDetails = ( ) => setIsProductDetailsOpen ( false ) ;
12
14
15
+ //Product detail: show product details
16
+ const [ productToShow , setProductToShow ] = useState ( { } ) ;
13
17
return (
14
18
< ShoppingCartContext . Provider
15
19
value = { {
@@ -18,6 +22,8 @@ export const ShoppingCartProvider = ({ children }) => {
18
22
openProductDetails,
19
23
closeProductDetails,
20
24
isProductDetailsOpen,
25
+ productToShow,
26
+ setProductToShow,
21
27
} }
22
28
>
23
29
{ children }
You can’t perform that action at this time.
0 commit comments