diff --git a/src/views/Products/layouts/Desktop/Main.js b/src/views/Products/layouts/Desktop/Main.js index e41bb9a..45ba2ad 100644 --- a/src/views/Products/layouts/Desktop/Main.js +++ b/src/views/Products/layouts/Desktop/Main.js @@ -13,6 +13,7 @@ import moment from "jalali-moment"; import dropdownIcon from "../../../../assets/icons/dropdown-blue.svg"; import Posts from "./Posts"; +import Pagination from "./Pagination"; export const Main = ({ books, @@ -131,7 +132,7 @@ export const Main = ({ const [posts, setPosts] = useState([]); const [loading, setLoading] = useState(false); const [currentPage, setCurrentPage] = useState(1); - const [postsPerPage, setPostsPerPage] = useState(10); + const [postsPerPage] = useState(10); useEffect(() => { const fetchPosts = async () => { @@ -144,6 +145,14 @@ export const Main = ({ fetchPosts(); }, []); + // get current post + const indexOfLastPost = currentPage * postsPerPage; + const indexOfFirstPost = indexOfLastPost - postsPerPage; + const currentPosts = posts.slice(indexOfFirstPost, indexOfLastPost); + + // change page + const paginate = (pageNumber) => setCurrentPage(pageNumber); + return (
paginate(number)} className=""> + {number} +
+