feat(doctors): add loading state management and pass filter to sendReq
This commit is contained in:
@@ -18,7 +18,7 @@ function Content({
|
|||||||
const { matchedState } = getStateInfoClient();
|
const { matchedState } = getStateInfoClient();
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
handleClose();
|
handleClose();
|
||||||
sendReq();
|
sendReq(filter);
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateData = (name, value) => {
|
const updateData = (name, value) => {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { QueryForDoctorsFilter, QueryForDoctorsReq } from "@/helper";
|
|||||||
import { request } from "@/services/response";
|
import { request } from "@/services/response";
|
||||||
import FilterLocate from "./FilterLocate";
|
import FilterLocate from "./FilterLocate";
|
||||||
|
|
||||||
function Head({ filter, setFilter, setPage, setDoctors }) {
|
function Head({ filter, setFilter, setPage, setDoctors, setLoading }) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const setDataInURL = (newFilter) => {
|
const setDataInURL = (newFilter) => {
|
||||||
@@ -38,6 +38,7 @@ function Head({ filter, setFilter, setPage, setDoctors }) {
|
|||||||
filteredName.page = 1;
|
filteredName.page = 1;
|
||||||
filteredName.limit = 12;
|
filteredName.limit = 12;
|
||||||
setPage(1);
|
setPage(1);
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
return request
|
return request
|
||||||
.getDoctors(filteredName)
|
.getDoctors(filteredName)
|
||||||
@@ -47,6 +48,9 @@ function Head({ filter, setFilter, setPage, setDoctors }) {
|
|||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
throw err;
|
throw err;
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
setLoading(false);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ function DoctorsPage({ matchedCity, matchedState, list }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const [filter, setFilter] = useState(defaultFilter);
|
const [filter, setFilter] = useState(defaultFilter);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="pt-[95px] sm:pt-[120px] padding-responsive">
|
<div className="pt-[95px] sm:pt-[120px] padding-responsive">
|
||||||
@@ -54,6 +55,7 @@ function DoctorsPage({ matchedCity, matchedState, list }) {
|
|||||||
setPage={setPage}
|
setPage={setPage}
|
||||||
setFilter={setFilter}
|
setFilter={setFilter}
|
||||||
setDoctors={setDoctors}
|
setDoctors={setDoctors}
|
||||||
|
setLoading={setLoading}
|
||||||
matchedCity={matchedCity}
|
matchedCity={matchedCity}
|
||||||
matchedState={matchedState}
|
matchedState={matchedState}
|
||||||
/>
|
/>
|
||||||
@@ -64,6 +66,8 @@ function DoctorsPage({ matchedCity, matchedState, list }) {
|
|||||||
filter={filter}
|
filter={filter}
|
||||||
setPage={setPage}
|
setPage={setPage}
|
||||||
doctors={doctors}
|
doctors={doctors}
|
||||||
|
loading={loading}
|
||||||
|
setLoading={setLoading}
|
||||||
setDoctors={setDoctors}
|
setDoctors={setDoctors}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -13,8 +13,10 @@ function ListDoctors({
|
|||||||
doctors,
|
doctors,
|
||||||
setPage,
|
setPage,
|
||||||
setDoctors,
|
setDoctors,
|
||||||
|
loading: filterLoading,
|
||||||
}) {
|
}) {
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const isLoading = loading || filterLoading;
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const changePage =async (_, num) => {
|
const changePage =async (_, num) => {
|
||||||
@@ -54,14 +56,14 @@ function ListDoctors({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="mt-[24px] sm:mt-[37px] md:mt-[50px] lg:mt-[64px]">
|
<div className="mt-[24px] sm:mt-[37px] md:mt-[50px] lg:mt-[64px] relative">
|
||||||
{doctors && doctors.length ? (
|
{doctors && doctors.length ? (
|
||||||
<ul className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-[24px]">
|
<ul className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-[24px]">
|
||||||
{doctors?.map((doctor, idx) => (
|
{doctors?.map((doctor, idx) => (
|
||||||
<ItemDoctor
|
<ItemDoctor
|
||||||
key={doctor.id}
|
key={doctor.id}
|
||||||
doctor={doctor}
|
doctor={doctor}
|
||||||
loading={loading}
|
loading={isLoading}
|
||||||
priority={idx < 3}
|
priority={idx < 3}
|
||||||
setDoctors={setDoctors}
|
setDoctors={setDoctors}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user