From 845db52e31f0bc5cc1642e239e004b61a7cc0176 Mon Sep 17 00:00:00 2001 From: Ehsan Date: Wed, 14 May 2025 01:34:10 +0330 Subject: [PATCH] handle pagination in specialities and fix warning --- app/component/Pagination.js | 15 ++++++----- app/globals.css | 6 ++++- components/specialties/index.js | 10 +------- .../specialties/list/ItemSpecialties.js | 17 +++++-------- components/specialties/list/index.js | 25 +++++++++++++------ 5 files changed, 38 insertions(+), 35 deletions(-) diff --git a/app/component/Pagination.js b/app/component/Pagination.js index 76a5264..8b2177e 100644 --- a/app/component/Pagination.js +++ b/app/component/Pagination.js @@ -1,10 +1,13 @@ import { Pagination as PaginationMUI } from "@mui/material"; -function Pagination() { +function Pagination({ page, setPage, list, itemsPerPage }) { + const handleChange = (_, value) => setPage(value); + return ( { - setTimeout(() => { - setLoading(false); - }, 2000); - }, []); - - // Filter specialties when search query changes useEffect(() => { if (searchQuery.trim() === "") { setFilteredSpecialties(specialtiesData); @@ -42,7 +34,7 @@ function SpecialtiesPage() { > - + ); } diff --git a/components/specialties/list/ItemSpecialties.js b/components/specialties/list/ItemSpecialties.js index 57ca669..a1f377d 100644 --- a/components/specialties/list/ItemSpecialties.js +++ b/components/specialties/list/ItemSpecialties.js @@ -1,7 +1,6 @@ -import TextLoading from "@/app/component/loading/Text"; import Link from "next/link"; -function ItemSpecialties({ data, loading }) { +function ItemSpecialties({ data }) { return (
  • - -

    {data.name}

    -
    - -

    - {data.number_of_doctors} پزشک -

    -
    +

    {data.name}

    +

    + {data.number_of_doctors} پزشک +

  • ); diff --git a/components/specialties/list/index.js b/components/specialties/list/index.js index f1b4040..1e15427 100644 --- a/components/specialties/list/index.js +++ b/components/specialties/list/index.js @@ -1,8 +1,16 @@ import MenuS from "@/components/icons/MenuS"; import Pagination from "@/app/component/Pagination"; import ItemSpecialties from "./ItemSpecialties"; +import { useState } from "react"; + +function List({ specialties = [] }) { + const [page, setPage] = useState(1); + const itemsPerPage = 24; + + const startIndex = (page - 1) * itemsPerPage; + const endIndex = startIndex + itemsPerPage; + const currentList = specialties.filter((_, i) => i >= startIndex && i < endIndex); -function List({ loading, specialties = [] }) { return (
    @@ -21,17 +29,18 @@ function List({ loading, specialties = [] }) { gap-x-[16px] md:gap-x-[20px] lg:gap-x-[24px] gap-y-[16px] sm:gap-y-[24px] md:gap-y-[32px] lg:gap-y-[40px]" > - {specialties.map((speciality) => ( - + {currentList.map((speciality) => ( + ))} )}
    - +
    );