From 6d98141c394c534a1b3729b0111492bede37ceea Mon Sep 17 00:00:00 2001 From: victorAnumudu Date: Fri, 22 Mar 2024 10:40:57 +0100 Subject: [PATCH] offer interest refresh started --- src/components/MarketPlace/MainSection.jsx | 35 ++++++ .../Pagination/NewPaginatedList.jsx | 101 ++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 src/components/Pagination/NewPaginatedList.jsx diff --git a/src/components/MarketPlace/MainSection.jsx b/src/components/MarketPlace/MainSection.jsx index f251cd7..4d76c7b 100644 --- a/src/components/MarketPlace/MainSection.jsx +++ b/src/components/MarketPlace/MainSection.jsx @@ -4,6 +4,7 @@ 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"; export default function MainSection({ className, @@ -120,6 +121,40 @@ export default function MainSection({ + {/* {products?.length && + + { + ({data})=>( +
+
+ { + data.map((datum, index) => ( +
+ +
+ )) + } +
+
+ ) + } +
+ } */} ); diff --git a/src/components/Pagination/NewPaginatedList.jsx b/src/components/Pagination/NewPaginatedList.jsx new file mode 100644 index 0000000..9283b6c --- /dev/null +++ b/src/components/Pagination/NewPaginatedList.jsx @@ -0,0 +1,101 @@ +import { useEffect, useState } from "react"; + +const data1 = []; + +export default function NewPaginatedList({ + data = data1, + itemsPerPage = 5, + filterItem, + tableTitle, + children, +}) { + const [searchTerm, setSearchTerm] = useState(""); + const [filteredData, setFilteredData] = useState(data); + + const [currentPage, setCurrentPage] = useState(0); + const [newData, setNewData] = useState([]); + + const numberOfSelection = itemsPerPage; + + const handlePrev = () => { + if (currentPage != 0) { + setCurrentPage((prev) => prev - numberOfSelection); + } + }; + const handleNext = () => { + if (currentPage < data.length) { + setCurrentPage((prev) => prev + numberOfSelection); + } + }; + + const handleSearch = ({ target: { value } }, name) => { + setSearchTerm(value); + let newFilteredData = data.filter((item) => + item[name].toLowerCase().startsWith(value.toLowerCase()) + ); + setFilteredData(newFilteredData); + setCurrentPage(0); + }; + + useEffect(() => { + setNewData( + filteredData?.slice(currentPage, numberOfSelection + currentPage) + ); + }, [currentPage, filteredData]); + console.log("newData", newData, filteredData); + return ( +
+

{tableTitle}

+ + {data.length > 0 && filterItem && ( +
+ {filterItem.map((item, index) => ( + + ))} +
+ )} + + {children({ data: newData })} + + {/* show prev and next button if data exist */} + {data.length > 0 && ( +
+ + +
+ )} +
+ ); +} -- 2.34.1