@@ -5,10 +5,13 @@ import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
55import ArrowCircleRightIcon from '@mui/icons-material/ArrowCircleRight' ;
66import FavoriteIcon from '@mui/icons-material/Favorite' ;
77import { useLoaderData } from 'react-router-dom'
8+ import { useDispatch } from 'react-redux' ;
9+ import { addToCart } from '../../redux/amazonSlice' ;
810
911
1012
1113const Products = ( ) => {
14+ const disptach = useDispatch ( ) ;
1215 const data = useLoaderData ( ) ;
1316 const productsData = data . data ;
1417
@@ -37,8 +40,8 @@ const Products = () => {
3740 src = { item . image }
3841 alt = 'ProductImg'
3942 />
40- < ul className = 'w-full h-36 bg-gray-100 absolute -bottom-[170px ]
41- group-hover:bottom-0 duration-700 flex flex-col items-end justify-center gap-2
43+ < ul className = 'w-full h-36 bg-gray-100 absolute -bottom-[168px ]
44+ group-hover:bottom-2 duration-700 flex flex-col items-end justify-center gap-2
4245 px-2 border-1 border-r' >
4346 < li className = 'productli' >
4447 Compare{ ' ' }
@@ -72,7 +75,7 @@ const Products = () => {
7275 </ li >
7376 </ ul >
7477 </ div >
75- < div className = 'px-4 z-10 bg-white' >
78+ < div className = 'px-4 py-4 z-10 bg-white' >
7679 < div className = 'flex items-center justify-between' >
7780 < h2 className = 'tracking-wide text-lg text-amazon_blue
7881 font-medium' >
@@ -90,11 +93,20 @@ const Products = () => {
9093 < StarBorderIcon />
9194 </ div >
9295 < div >
93- < button className = 'w-full font-medium text-base bg-gradient-to-tr
96+ < button onClick = { ( ) => disptach ( addToCart ( {
97+ id :item . id ,
98+ title :item . title ,
99+ description :item . description ,
100+ price :item . price ,
101+ category :item . category ,
102+ image :item . image ,
103+ quantity :1 ,
104+ } ) ) }
105+ className = 'w-full font-medium text-base bg-gradient-to-tr
94106 from-yellow-400 to yellow-500 border hover:from-yellow-300 hover:to-yellow-600
95107 active:from-yellow-400 active:to-yellow-500 duration-200 py-1.5 rounded-md
96108 mt-3' >
97- Add to
109+ Add to Cart
98110 </ button >
99111 </ div >
100112 </ div >
0 commit comments