Skip to content

Commit

Permalink
applied first visit
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulg1254 committed Sep 4, 2024
1 parent f48718a commit 168e475
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/pages/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const Block: React.FC = () => {
const [showAllBlocks, setShowAllBlocks] = useState("All");
const [statusValue, setStatusValue] = useState(Status.ACTIVE);
const [pageSize, setPageSize] = React.useState<string | number>(10);
const [isFirstVisit, setIsFirstVisit] = useState(true);

const [filters, setFilters] = useState({
name: searchKeyword,
Expand Down Expand Up @@ -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);
Expand All @@ -252,7 +256,7 @@ const Block: React.FC = () => {
if (stateCode) {
getFilteredCohortData();
}
}, [searchKeyword, pageLimit, pageOffset, stateCode]);
}, [isFirstVisit,searchKeyword, pageLimit, pageOffset, stateCode]);

const fetchBlocks = async () => {
try {
Expand Down Expand Up @@ -486,7 +490,6 @@ const Block: React.FC = () => {
setPageOffset(Numbers.ZERO);
setPageCount(Numbers.ONE);

setLoading(true);
const selectedDistrict = event.target.value;
setSelectedDistrict(selectedDistrict);
setShowAllBlocks("");
Expand All @@ -500,7 +503,6 @@ const Block: React.FC = () => {
setSelectedCohortId(cohortId);

await getCohortSearchBlock(selectedDistrict);
setLoading(false);
};

console.log("selectedCohortId", selectedCohortId);
Expand Down

0 comments on commit 168e475

Please sign in to comment.