Skip to content

Commit

Permalink
fix: fix report search and infinite scroll limit
Browse files Browse the repository at this point in the history
  • Loading branch information
okorie2 committed Oct 24, 2023
1 parent df0097a commit 60fd6de
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
15 changes: 7 additions & 8 deletions src/app/modules/home-module/components/Charts/chartsGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down Expand Up @@ -72,16 +72,13 @@ 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,
storeInCrudData: true,
filterString: getFilterString(),
});
}
// }
};

const reloadData = async () => {
Expand All @@ -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]);
Expand Down
12 changes: 7 additions & 5 deletions src/app/modules/home-module/components/Datasets/datasetsGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
12 changes: 7 additions & 5 deletions src/app/modules/home-module/components/Reports/reportsGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]);
Expand Down

0 comments on commit 60fd6de

Please sign in to comment.