Skip to content

Commit

Permalink
added debopuncing for that 3 apis
Browse files Browse the repository at this point in the history
  • Loading branch information
i0am0arunava committed Jan 6, 2025
1 parent 2323a97 commit 6f9e820
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ ESLINT_NO_DEV_ERRORS=true
CARE_CDN_URL="https://egov-s3-facility-10bedicu.s3.amazonaws.com https://egov-s3-patient-data-10bedicu.s3.amazonaws.com http://localhost:4566"
REACT_ALLOWED_LOCALES="en,hi,ta,ml,mr,kn"

REACT_ENABLED_APPS=""
REACT_ENABLED_APPS= ""
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions src/pages/FacilityOrganization/FacilityOrganizationView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from "@tanstack/react-query";
import { Link } from "raviger";
import { useState } from "react";
import { useEffect, useState } from "react";

import CareIcon from "@/CAREUI/icons/CareIcon";

Expand All @@ -11,6 +11,8 @@ import { Input } from "@/components/ui/input";

import Pagination from "@/components/Common/Pagination";

import useDebounce from "@/hooks/useDebounce";

import routes from "@/Utils/request/api";
import query from "@/Utils/request/query";

Expand All @@ -25,8 +27,15 @@ interface Props {
export default function FacilityOrganizationView({ id, facilityId }: Props) {
const [page, setPage] = useState(1);
const [searchQuery, setSearchQuery] = useState("");
const [debouncedQuery, setDebouncedQuery] = useState("");
const limit = 12; // 3x4 grid
const debounceQuery = useDebounce((newParams) => {
setDebouncedQuery(newParams);
}, 500);

useEffect(() => {
debounceQuery(searchQuery);
}, [searchQuery]);
const { data: children, isLoading } = useQuery({
queryKey: [
"facilityOrganization",
Expand All @@ -35,15 +44,15 @@ export default function FacilityOrganizationView({ id, facilityId }: Props) {
id,
page,
limit,
searchQuery,
debouncedQuery,
],
queryFn: query(routes.facilityOrganization.list, {
pathParams: { facilityId, organizationId: id },
queryParams: {
parent: id,
offset: (page - 1) * limit,
limit,
name: searchQuery || undefined,
name: debouncedQuery || undefined,
},
}),
});
Expand Down
20 changes: 16 additions & 4 deletions src/pages/Organization/OrganizationFacilities.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useQuery } from "@tanstack/react-query";
import { Link } from "raviger";
import { useEffect, useState } from "react";

import CareIcon from "@/CAREUI/icons/CareIcon";

Expand All @@ -9,6 +10,7 @@ import { Input } from "@/components/ui/input";

import { Avatar } from "@/components/Common/Avatar";

import useDebounce from "@/hooks/useDebounce";
import useFilters from "@/hooks/useFilters";

import routes from "@/Utils/request/api";
Expand All @@ -30,15 +32,25 @@ export default function OrganizationFacilities({
const { qParams, Pagination, advancedFilter, resultsPerPage, updateQuery } =
useFilters({ limit: 14, cacheBlacklist: ["facility"] });

const [debouncedParams, setDebouncedParams] = useState(qParams);

const debounceParams = useDebounce((newParams) => {
setDebouncedParams(newParams);
}, 500);

useEffect(() => {
debounceParams(qParams);
}, [JSON.stringify(qParams)]);

const { data: facilities, isLoading } = useQuery({
queryKey: ["organizationFacilities", id, qParams],
queryKey: ["organizationFacilities", id, debouncedParams],
queryFn: query(routes.facility.list, {
queryParams: {
page: qParams.page,
page: debouncedParams.page,
limit: resultsPerPage,
offset: (qParams.page - 1) * resultsPerPage,
offset: (debouncedParams.page - 1) * resultsPerPage,
organization: id,
name: qParams.name,
name: debouncedParams.name,
...advancedFilter.filter,
},
}),
Expand Down
18 changes: 14 additions & 4 deletions src/pages/Organization/OrganizationView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from "@tanstack/react-query";
import { Link } from "raviger";
import { useState } from "react";
import { useEffect, useState } from "react";

import CareIcon from "@/CAREUI/icons/CareIcon";

Expand All @@ -11,6 +11,8 @@ import { Input } from "@/components/ui/input";

import Pagination from "@/components/Common/Pagination";

import useDebounce from "@/hooks/useDebounce";

import query from "@/Utils/request/query";
import { Organization, getOrgLabel } from "@/types/organization/organization";
import organizationApi from "@/types/organization/organizationApi";
Expand All @@ -25,16 +27,24 @@ interface Props {
export default function OrganizationView({ id, navOrganizationId }: Props) {
const [page, setPage] = useState(1);
const [searchQuery, setSearchQuery] = useState("");
const limit = 12; // 3x4 grid

const [debouncedQuery, setDebouncedQuery] = useState("");

const limit = 12; // 3x4 grid
const debounceQuery = useDebounce((newParams) => {
setDebouncedQuery(newParams);
}, 500);
useEffect(() => {
debounceQuery(searchQuery);
}, [searchQuery]);
const { data: children, isLoading } = useQuery({
queryKey: ["organization", id, "children", page, limit, searchQuery],
queryKey: ["organization", id, "children", page, limit],
queryFn: query(organizationApi.list, {
queryParams: {
parent: id,
offset: (page - 1) * limit,
limit,
name: searchQuery || undefined,
name: debouncedQuery || undefined,
},
}),
});
Expand Down

0 comments on commit 6f9e820

Please sign in to comment.