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

added wishlist empty message wrapper (fixed #133) #245

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Changes from all 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
163 changes: 68 additions & 95 deletions src/Components/SavedItems.jsx
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;