import { React, useState, useEffect } from "react"; import { AddToList, RemoveList } from "../action/List"; import { useSelector, useDispatch } from "react-redux"; import { Link } from "react-router-dom"; import Added from "../imgs/red-heart.png"; import Add from "../imgs/heart.png"; import Footer from "./Footer"; import rating from "../imgs/rating.png"; import Navbar from "./Navbar"; import empty from "../imgs/empty.png"; import { NavLink } from "react-router-dom"; import LowerNav from "./LowerNav"; import "./lists.css"; function Lists() { const [AddedIds, setAddedIds] = useState([]); const ListItems = useSelector((state) => state.ItemsAdded.ListItems); const dispatch = useDispatch(); document.title = "Wishlist section" useEffect(() => { // Update the added ids whenever the list items change const ids = ListItems.map((item) => item.id); setAddedIds(ids); }, [ListItems]); const isAdded = (itemId) => { // Check if the item id is in the added ids return AddedIds.includes(itemId); }; useEffect(() => { window.scrollTo(0, 0); }, []); return ( <>

Wishlist

It's empty here!

"Don't let your wishlist collect dust. Add some items that bring joy to your life and watch as they become a reality with just a few clicks."

{ListItems && ListItems.length > 0 && ListItems.map((items) => { return (
{ if (!isAdded(items.id)) { dispatch(AddToList(items)); } else { dispatch(RemoveList(items.id)); } }} src={isAdded(items.id) ? Added : Add} className="add-list2" />

{items.title.length >= 32 ? items.title.slice(0, 32) + ".." : items.title}

{items.category}

5

${items.price}

${Math.round(items.price * 1.66)}

(60% OFF)

); })}
); } export default Lists;