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 (
{mappedArray.map(({ key, value }) => ( tabHandler(key)} className={`md:text-[18px] text-md text-dark-gray dark:text-white hover:text-pink border-b hover:border-pink font-medium cursor-pointer ${ tab === key ? "text-pink border-pink" : " border-transparent" }`} > {value} ))}
{/* market categories on screen smaller than large screen */}
{/* contentDisplay toggler */}
setContentDisplay((prev) => (prev == "grid" ? "list" : "grid")) } src={contentDisplay == "grid" ? ListView : GridView} className="w-full h-full cursor-pointer" alt="view" />
{/* end of contentDisplay toggler */}
{/* OLD MARKET JOB LISTING */} {/*
{({ datas, index }) => (
)}
*/} {/* END OF OLD MARKET JOB LISTING */} {products?.length ? { ({data})=>(
{ data.map((datum, index) => (
)) }
) }
// // { // ({dataToShow})=>( //
//
// { // dataToShow.map((datum, index) => ( //
// //
// )) // } //
//
// ) // } //
:
No Jobs Found!
}
); }