import React, { useEffect, useMemo, useState } from "react"; import GridView from "../../assets/images/grid-view.svg"; import ListView from "../../assets/images/list-view.png"; import AvailableJobsCard from "../Cards/AvailableJobsCard"; import DataIteration from "../Helpers/DataIteration"; import SelectBox from "../Helpers/SelectBox"; import NewPaginatedList from "../Pagination/NewPaginatedList"; import InfiniteScroll from "../infiniteScroll/InfiniteScroll"; export default function MainSection({ className, marketPlaceProduct, image_server, categories, }) { // Creating All cart.. let marketCategories = useMemo( () => ({ All: "All Categories", ...categories }), [categories] ); const [tab, setTab] = useState(Object.keys(marketCategories)[0]); let [contentDisplay, setContentDisplay] = useState("grid"); // STATE TO HOLD LIST VIEW STYLE // Convert to array in order to map const mappedArray = Object.entries(marketCategories).map(([key, value]) => { return { key, value }; }); const [products, setProducts] = useState([]); const tabHandler = (value) => { setTab(value); }; // Handles the category selection on mobile view const handleSetCategory = (value) => { for (let i in marketCategories) { if (marketCategories[i] == value) { setTab(i); } } }; useEffect(() => { if (tab === "All") { setProducts(marketPlaceProduct); } else { const filteredProducts = marketPlaceProduct.filter((product) => product.category.includes(tab) ); setProducts(filteredProducts); } }, [tab, marketPlaceProduct, categories, marketCategories]); return (