From 60fd6de33d2aab8c087679811b3352426faf7f95 Mon Sep 17 00:00:00 2001 From: okorie2 Date: Tue, 24 Oct 2023 11:56:13 +0100 Subject: [PATCH] fix: fix report search and infinite scroll limit --- .../home-module/components/Charts/chartsGrid.tsx | 15 +++++++-------- .../components/Datasets/datasetsGrid.tsx | 12 +++++++----- .../components/Reports/reportsGrid.tsx | 12 +++++++----- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/app/modules/home-module/components/Charts/chartsGrid.tsx b/src/app/modules/home-module/components/Charts/chartsGrid.tsx index 36752a353..2f2714abc 100644 --- a/src/app/modules/home-module/components/Charts/chartsGrid.tsx +++ b/src/app/modules/home-module/components/Charts/chartsGrid.tsx @@ -43,7 +43,7 @@ export default function ChartsGrid(props: Props) { const loadChartsCount = useStoreActions( (actions) => actions.charts.ChartsCount.fetch ); - const ChartsCount = useStoreState( + const chartsCount = useStoreState( (state) => get(state, "charts.ChartsCount.data.count", 0) as number ); @@ -72,8 +72,6 @@ export default function ChartsGrid(props: Props) { }; const loadData = async () => { - //refrain from loading data if all the data is loaded - // if (loadedCharts.length !== ChartsCount) { if (token) { await loadCharts({ token, @@ -81,7 +79,6 @@ export default function ChartsGrid(props: Props) { filterString: getFilterString(), }); } - // } }; const reloadData = async () => { @@ -103,10 +100,12 @@ export default function ChartsGrid(props: Props) { React.useEffect(() => { //load data if intersection observer is triggered - if (isObserved) { - if (loadedCharts.length !== ChartsCount) { - //update the offset value for the next load - setOffset(offset + limit); + if (chartsCount > limit) { + if (isObserved) { + if (loadedCharts.length !== chartsCount) { + //update the offset value for the next load + setOffset(offset + limit); + } } } }, [isObserved]); diff --git a/src/app/modules/home-module/components/Datasets/datasetsGrid.tsx b/src/app/modules/home-module/components/Datasets/datasetsGrid.tsx index 61aee4798..e1625b9e1 100644 --- a/src/app/modules/home-module/components/Datasets/datasetsGrid.tsx +++ b/src/app/modules/home-module/components/Datasets/datasetsGrid.tsx @@ -97,11 +97,13 @@ export default function DatasetsGrid(props: Props) { React.useEffect(() => { //load data if intersection observer is triggered - if (isObserved) { - console.log(loadedDatasets.length, datasetCount); - if (loadedDatasets.length !== datasetCount) { - //update the offset value for the next load - setOffset(offset + limit); + if (datasetCount > limit) { + if (isObserved) { + console.log(loadedDatasets.length, datasetCount); + if (loadedDatasets.length !== datasetCount) { + //update the offset value for the next load + setOffset(offset + limit); + } } } }, [isObserved]); diff --git a/src/app/modules/home-module/components/Reports/reportsGrid.tsx b/src/app/modules/home-module/components/Reports/reportsGrid.tsx index 704b71976..933853980 100644 --- a/src/app/modules/home-module/components/Reports/reportsGrid.tsx +++ b/src/app/modules/home-module/components/Reports/reportsGrid.tsx @@ -68,7 +68,7 @@ export default function ReportsGrid(props: Props) { const loadData = async () => { //refrain from loading data if all the data is loaded - if (loadedReports.length !== reportsCount && token) { + if (token) { await loadReports({ token, storeInCrudData: true, @@ -88,10 +88,12 @@ export default function ReportsGrid(props: Props) { React.useEffect(() => { //load data if intersection observer is triggered - if (isObserved) { - if (loadedReports.length !== reportsCount) { - //update the offset value for the next load - setOffset(offset + limit); + if (reportsCount > limit) { + if (isObserved) { + if (loadedReports.length !== reportsCount) { + //update the offset value for the next load + setOffset(offset + limit); + } } } }, [isObserved]);