From 168e475c785322905435cf1ae3fe44a19ea5673b Mon Sep 17 00:00:00 2001 From: Rahul Garud Date: Wed, 4 Sep 2024 14:02:15 +0530 Subject: [PATCH] applied first visit --- src/pages/block.tsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/pages/block.tsx b/src/pages/block.tsx index 1baaaaa0..85ec322f 100644 --- a/src/pages/block.tsx +++ b/src/pages/block.tsx @@ -118,6 +118,7 @@ const Block: React.FC = () => { const [showAllBlocks, setShowAllBlocks] = useState("All"); const [statusValue, setStatusValue] = useState(Status.ACTIVE); const [pageSize, setPageSize] = React.useState(10); + const [isFirstVisit, setIsFirstVisit] = useState(true); const [filters, setFilters] = useState({ name: searchKeyword, @@ -234,11 +235,14 @@ const Block: React.FC = () => { .filter((district: { label: any }) => districtNameArr.includes(district.label) ); - if ( - filteredDistrictData.length > 0 && - selectedDistrict !== t("COMMON.ALL") - ) { - setSelectedDistrict(filteredDistrictData[0].value); + if (isFirstVisit) { + if ( + filteredDistrictData.length > 0 && + selectedDistrict !== t("COMMON.ALL") + ) { + setSelectedDistrict(filteredDistrictData[0].value); + } + setIsFirstVisit(false); } setDistrictData(filteredDistrictData); setLoading(false); @@ -252,7 +256,7 @@ const Block: React.FC = () => { if (stateCode) { getFilteredCohortData(); } - }, [searchKeyword, pageLimit, pageOffset, stateCode]); + }, [isFirstVisit,searchKeyword, pageLimit, pageOffset, stateCode]); const fetchBlocks = async () => { try { @@ -486,7 +490,6 @@ const Block: React.FC = () => { setPageOffset(Numbers.ZERO); setPageCount(Numbers.ONE); - setLoading(true); const selectedDistrict = event.target.value; setSelectedDistrict(selectedDistrict); setShowAllBlocks(""); @@ -500,7 +503,6 @@ const Block: React.FC = () => { setSelectedCohortId(cohortId); await getCohortSearchBlock(selectedDistrict); - setLoading(false); }; console.log("selectedCohortId", selectedCohortId);