-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #245 from DharshiBalasubramaniyam/wishlist
added wishlist empty message wrapper (fixed #133)
- Loading branch information
Showing
1 changed file
with
68 additions
and
95 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,109 +1,82 @@ | ||
|
||
import React from "react" | ||
import {useContext} from "react" | ||
import {SavedContext} from "../Context/SavedContext" | ||
import { useContext } from "react" | ||
import { SavedContext } from "../Context/SavedContext" | ||
import { ShopContext } from "../Context/ShopContext"; | ||
import { Link } from "react-router-dom"; | ||
|
||
|
||
const SavedItems=()=>{ | ||
const {all_products,listItem,AddToList,RemoveFromList,getListQuantity}=useContext(SavedContext) | ||
const {AddToCart}=useContext(ShopContext) | ||
const SavedItems = () => { | ||
const { all_products, listItem, AddToList, RemoveFromList, getListQuantity } = useContext(SavedContext) | ||
const { AddToCart } = useContext(ShopContext) | ||
|
||
|
||
return( | ||
<> | ||
|
||
<div className="flex my-50"><p className="font-normal ">Total products Wishlisted: </p><p className="font-bold">{getListQuantity()}</p></div> | ||
|
||
<div className="grid grid-cols-3 "> | ||
{ | ||
all_products.map((item) => { | ||
if (listItem[item.id] > 0) { | ||
return( | ||
<div className="h-220 w-94 bg-white space-x-7" key={item.id}> | ||
<img src={item.image} alt={item.name} className="h-150 w-92"/> | ||
<div className="h-150 w-92"> | ||
<p className="font-semibold font-serif"> | ||
{(item.name.length > 40) ? ( | ||
// Truncate the name to the maximum length | ||
item.name.substring(0, 40) + "..." | ||
): (item.name) | ||
} | ||
</p> | ||
<p className="font-mono font-bold">Category: {item.category}</p> | ||
<div className="grid grid-cols-2"> | ||
<div><p className="font-bold text-green-900">${item.new_price}</p></div> | ||
<div><p className="line-through text-red-600">${item.old_price}</p></div> | ||
|
||
</div> | ||
<div className="flex space-x-20"> | ||
|
||
<div><button onClick={()=>{ | ||
RemoveFromList(item.id) | ||
}} className="bg-blue-950 text-white p-4 font-bold">Remove</button></div> | ||
<div><button className="bg-red-700 text-white p-4 font-extrabold" onClick={()=>{ | ||
AddToCart(item.id) | ||
}}>Add to Cart</button></div> | ||
|
||
</div> | ||
</div> | ||
|
||
|
||
</div> | ||
) | ||
} | ||
}) | ||
} | ||
|
||
|
||
|
||
</div> | ||
|
||
</> | ||
) | ||
} | ||
|
||
export default SavedItems; | ||
const wishlistItems = all_products.filter(item => listItem[item.id] > 0) | ||
console.log(wishlistItems) | ||
|
||
/*function CardComponent(item){ | ||
return( | ||
<div className="h-220 w-94 bg-white"> | ||
<img src={item.image} alt={item.name} className="h-150 w-92"/> | ||
<p className="font-semibold">{item.name}</p> | ||
<p className="font-normal">#Category:{item.category}</p> | ||
<div className="flex justify-between"> | ||
<p className="font-bold text-green-900">${item.new_price}</p> | ||
<p className="line-through text-red-600">${item.old_price}</p> | ||
</div> | ||
</div> | ||
) | ||
}*/ | ||
|
||
return ( | ||
<> | ||
|
||
{ | ||
wishlistItems.length === 0 ? ( | ||
<div className="grid place-items-center w-full py-20"> | ||
<h1 className="text-lg text-orange-500 mb-2">Your wishlist is empty!</h1> | ||
<p className="text-center">Seems like you do not have any wishes here. <br /> Make a wish!</p> | ||
<Link to="/"><button className="px-5 py-3 bg-orange-500 rounded-full my-4 text-white hover:bg-orange-600">Start shopping</button></Link> | ||
</div> | ||
) : <> | ||
<div className="flex my-4 px-4"> | ||
<p className="font-normal ">Total products Wishlisted: </p><p className="font-bold">{getListQuantity()}</p> | ||
</div> | ||
<div className="grid grid-cols-3 p-4"> | ||
{ | ||
wishlistItems.map((item) => { | ||
return ( | ||
<div className="h-220 w-94 bg-white space-x-7" key={item.id}> | ||
<img src={item.image} alt={item.name} className="h-150 w-92" /> | ||
<div className="h-150 w-92"> | ||
<p className="font-semibold font-serif"> | ||
{(item.name.length > 40) ? ( | ||
// Truncate the name to the maximum length | ||
item.name.substring(0, 40) + "..." | ||
) : (item.name) | ||
} | ||
</p> | ||
<p className="font-mono font-bold">Category: {item.category}</p> | ||
<div className="grid grid-cols-2"> | ||
<div><p className="font-bold text-green-900">${item.new_price}</p></div> | ||
<div><p className="line-through text-red-600">${item.old_price}</p></div> | ||
|
||
</div> | ||
<div className="flex space-x-20"> | ||
|
||
<div><button onClick={() => { | ||
RemoveFromList(item.id) | ||
}} className="bg-blue-950 text-white p-4 font-bold">Remove</button></div> | ||
<div><button className="bg-red-700 text-white p-4 font-extrabold" onClick={() => { | ||
AddToCart(item.id) | ||
}}>Add to Cart</button></div> | ||
|
||
</div> | ||
</div> | ||
|
||
|
||
</div> | ||
) | ||
}) | ||
} | ||
|
||
|
||
|
||
</div> | ||
</> | ||
} | ||
|
||
/*<div className="flex justify-between bg-pink-300"> | ||
{ | ||
all_products.map((item) => { | ||
if (listItem[item.id] > 0) { | ||
return( | ||
<CardComponent item={item}/> | ||
) | ||
} | ||
}) | ||
} | ||
|
||
</div>*/ | ||
|
||
</> | ||
) | ||
} | ||
|
||
/*<div className="flex justify-between"> | ||
<button onClick={()=>{ | ||
RemoveFromList(item.id) | ||
}} className="bg-blue-950 text-white">Remove</button> | ||
<button className="bg-red-700 text-white">Add to Cart</button> | ||
</div>*/ | ||
export default SavedItems; |