handle pagination in specialities and fix warning
This commit is contained in:
@@ -1,10 +1,13 @@
|
|||||||
import { Pagination as PaginationMUI } from "@mui/material";
|
import { Pagination as PaginationMUI } from "@mui/material";
|
||||||
|
|
||||||
function Pagination() {
|
function Pagination({ page, setPage, list, itemsPerPage }) {
|
||||||
|
const handleChange = (_, value) => setPage(value);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PaginationMUI
|
<PaginationMUI
|
||||||
// count={doctors.length / 12} org
|
count={list && itemsPerPage ? Math.ceil(list.length / itemsPerPage) : 20}
|
||||||
count={20}
|
page={page || 1}
|
||||||
|
onChange={setPage && handleChange}
|
||||||
color="primary"
|
color="primary"
|
||||||
sx={{
|
sx={{
|
||||||
"& .mui-8q7g72-MuiButtonBase-root-MuiPaginationItem-root": {
|
"& .mui-8q7g72-MuiButtonBase-root-MuiPaginationItem-root": {
|
||||||
@@ -13,9 +16,9 @@ function Pagination() {
|
|||||||
fontWeight: "500",
|
fontWeight: "500",
|
||||||
},
|
},
|
||||||
"& .mui-8q7g72-MuiButtonBase-root-MuiPaginationItem-root.Mui-selected":
|
"& .mui-8q7g72-MuiButtonBase-root-MuiPaginationItem-root.Mui-selected":
|
||||||
{
|
{
|
||||||
color: "#F8F8FF",
|
color: "#F8F8FF",
|
||||||
},
|
},
|
||||||
"& .MuiSvgIcon-root": {
|
"& .MuiSvgIcon-root": {
|
||||||
rotate: "180deg !important",
|
rotate: "180deg !important",
|
||||||
},
|
},
|
||||||
|
|||||||
+5
-1
@@ -842,4 +842,8 @@ html {
|
|||||||
top: 16px;
|
top: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* End Of Toastify */
|
/* End Of Toastify */
|
||||||
|
|
||||||
|
.text-item-head-white:hover .item-head {
|
||||||
|
color: #D7D8ED;
|
||||||
|
}
|
||||||
@@ -7,17 +7,9 @@ import HeadPageList from "@/app/component/head";
|
|||||||
import specialtiesData from "@/data/specialties.json";
|
import specialtiesData from "@/data/specialties.json";
|
||||||
|
|
||||||
function SpecialtiesPage() {
|
function SpecialtiesPage() {
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
const [searchQuery, setSearchQuery] = useState("");
|
const [searchQuery, setSearchQuery] = useState("");
|
||||||
const [filteredSpecialties, setFilteredSpecialties] = useState(specialtiesData);
|
const [filteredSpecialties, setFilteredSpecialties] = useState(specialtiesData);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setTimeout(() => {
|
|
||||||
setLoading(false);
|
|
||||||
}, 2000);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// Filter specialties when search query changes
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (searchQuery.trim() === "") {
|
if (searchQuery.trim() === "") {
|
||||||
setFilteredSpecialties(specialtiesData);
|
setFilteredSpecialties(specialtiesData);
|
||||||
@@ -42,7 +34,7 @@ function SpecialtiesPage() {
|
|||||||
>
|
>
|
||||||
<SmSearch placeholder="جستجوی تخصص" onSearch={handleSearch} />
|
<SmSearch placeholder="جستجوی تخصص" onSearch={handleSearch} />
|
||||||
</HeadPageList>
|
</HeadPageList>
|
||||||
<List loading={loading} specialties={filteredSpecialties} />
|
<List specialties={filteredSpecialties} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import TextLoading from "@/app/component/loading/Text";
|
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
|
||||||
function ItemSpecialties({ data, loading }) {
|
function ItemSpecialties({ data }) {
|
||||||
return (
|
return (
|
||||||
<li>
|
<li>
|
||||||
<Link
|
<Link
|
||||||
@@ -13,16 +12,12 @@ function ItemSpecialties({ data, loading }) {
|
|||||||
}}
|
}}
|
||||||
className="py-[17.5px] px-[12px] flex flex-col justify-center items-center gap-[16px]
|
className="py-[17.5px] px-[12px] flex flex-col justify-center items-center gap-[16px]
|
||||||
rounded-lg bg-[#FFF] shadow-[0px_1px_24.8px_0px_rgba(204,_204,_204,_0.18)]
|
rounded-lg bg-[#FFF] shadow-[0px_1px_24.8px_0px_rgba(204,_204,_204,_0.18)]
|
||||||
hover:bg-[#5559CE] transition-all duration-500 cursor-pointer hover-mode-item-speciality"
|
hover:bg-[#5559CE] transition-all text-item-head-white duration-500 cursor-pointer hover-mode-item-speciality"
|
||||||
>
|
>
|
||||||
<TextLoading loading={loading} width={70} height={18}>
|
<h2 className="text-[#3B3B3B] item-head text-[16px] font-bold text-center">{data.name}</h2>
|
||||||
<h2 className="text-[#3B3B3B] text-[16px] font-bold">{data.name}</h2>
|
<p className="text-[#7E7E7E] text-[14px] font-medium">
|
||||||
</TextLoading>
|
{data.number_of_doctors} پزشک
|
||||||
<TextLoading loading={loading} width={50} height={18}>
|
</p>
|
||||||
<p className="text-[#7E7E7E] text-[14px] font-medium">
|
|
||||||
{data.number_of_doctors} پزشک
|
|
||||||
</p>
|
|
||||||
</TextLoading>
|
|
||||||
</Link>
|
</Link>
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,8 +1,16 @@
|
|||||||
import MenuS from "@/components/icons/MenuS";
|
import MenuS from "@/components/icons/MenuS";
|
||||||
import Pagination from "@/app/component/Pagination";
|
import Pagination from "@/app/component/Pagination";
|
||||||
import ItemSpecialties from "./ItemSpecialties";
|
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 (
|
return (
|
||||||
<div className="bg-[#FAFAFA]">
|
<div className="bg-[#FAFAFA]">
|
||||||
<div className="flex items-center justify-center gap-[12px] pt-[24px] mb-[40px]">
|
<div className="flex items-center justify-center gap-[12px] pt-[24px] mb-[40px]">
|
||||||
@@ -21,17 +29,18 @@ function List({ loading, specialties = [] }) {
|
|||||||
gap-x-[16px] md:gap-x-[20px] lg:gap-x-[24px]
|
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]"
|
gap-y-[16px] sm:gap-y-[24px] md:gap-y-[32px] lg:gap-y-[40px]"
|
||||||
>
|
>
|
||||||
{specialties.map((speciality) => (
|
{currentList.map((speciality) => (
|
||||||
<ItemSpecialties
|
<ItemSpecialties data={speciality} key={speciality.id} />
|
||||||
loading={loading}
|
|
||||||
data={speciality}
|
|
||||||
key={speciality.id}
|
|
||||||
/>
|
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
)}
|
)}
|
||||||
<div className="mt-[48px] flex justify-center">
|
<div className="mt-[48px] flex justify-center">
|
||||||
<Pagination />
|
<Pagination
|
||||||
|
page={page}
|
||||||
|
setPage={setPage}
|
||||||
|
list={specialties}
|
||||||
|
itemsPerPage={itemsPerPage}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user