Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wishlist button in the product card (fixes #134) #185

Merged
merged 5 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/Components/Item.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import React from "react";
import React, { useContext } from "react";
import { Link } from "react-router-dom";
import { SavedContext } from "../Context/SavedContext"
import filled_Wishlist from '../assets/filled_wishlist.png'
import outlined_Wishlist from '../assets/outlined_wishlist.png'

const Item = (props) => {
const { image, name, new_price, old_price, id } = props.data;
const { AddToList, listItem } = useContext(SavedContext);

return (
<div className="m-5 cursor-pointer">
<div className="m-5 cursor-pointer transition delay-300 scale-100 hover:scale-95 relative">
<Link to={`/product/${id}`}>
<div className="transition delay-300 scale-100 hover:scale-95">
<div>
<img
onClick={window.scrollTo(0, 0)}
src={image}
Expand All @@ -23,6 +27,17 @@ const Item = (props) => {
</div>
</div>
</Link>
<button
onClick={() => {
AddToList(id);
}}
className="absolute top-0 right-0 mt-3 mr-3 bg-transparent border-none rounded"
>
{
listItem[id] ? <img src={filled_Wishlist} alt="wishlist" className="h-8 w-8 scale-100 hover:scale-95 rounded" /> :
<img src={outlined_Wishlist} alt="wishlist" className="h-8 w-8 scale-100 hover:scale-95 rounded" />
}
</button>
</div>
);
};
Expand Down
5 changes: 2 additions & 3 deletions src/Components/Popular.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import Item from "./Item";

const Popular = () => {
return (
<div className="grid items-center grid-cols-1 ps-20 sm:p-5 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-7">
<div>
<h1 className="text-4xl font-medium text-center font-Poppins mt-9 col-span-full">
Popular In Women
</h1>

<hr className="w-[200px] h-2 bg-gray-400 col-span-full rounded-xl" />
<div className="sm:flex">
<div className="grid items-center grid-cols-1 ps-20 sm:p-5 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-7">
{dataProduct.map((item) => {
return <Item data={item} key={item.id} />;
})}
Expand Down
3 changes: 2 additions & 1 deletion src/Context/SavedContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ const defaultWishlist = () => {
const SavedContextProvider = (props) => {
const [listItem, setListItem] = useState(defaultWishlist());
const AddToList = (id) => {

setListItem((prev) => {

const updatedState = { ...prev, [id]: true };
const updatedState = { ...prev, [id]: !listItem[id] };
console.log(updatedState);
return updatedState;

Expand Down
Binary file added src/assets/filled_wishlist.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/outlined_wishlist.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.