import { React, useEffect, useState } from "react"; import "../deals.css"; import Add from "./Img/heart.png"; import Added from "./Img/red-heart.png"; import rating from "./Img/rating.png"; import { AddToList, RemoveList } from "../../action/List"; import { useSelector, useDispatch } from "react-redux"; import Footer from "../Footer"; import { NavLink } from "react-router-dom"; import Spinner from "../Spinner"; import LowerNav from "../LowerNav"; function Women() { const [AllProducts, setAllProducts] = useState([]); const [AddedIds, setAddedIds] = useState([]); const [loading, setLoading] = useState(true); // add loading state const ListItems = useSelector((state) => state.ItemsAdded.ListItems); const dispatch = useDispatch(); useEffect(() => { const GetProducts = async () => { const data = await fetch( "https://fakestoreapi.com/products/category/women's%20clothing" ); const new_data = await data.json(); setLoading(false); setAllProducts(new_data); // Add a review number property to each item object const productsWithReviewNumber = new_data.map((item) => ({ ...item, reviewNumber: Math.floor(Math.random() * (150 - 50 + 1)) + 50, })); setAllProducts(productsWithReviewNumber); }; GetProducts(); }, []); 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); }; return (
Women's Clothing
{loading &&{items.title.length >= 32 ? items.title.slice(0, 32) + ".." : items.title}
{items.category}
{"5 " + "(" + items.reviewNumber + " reviews)"}
${items.price}
${Math.round(items.price * 1.66)}