Skip to content

Commit

Permalink
Merge pull request #1149 from microbiomedata/1034-url-query-fix
Browse files Browse the repository at this point in the history
Add debounce to fetch results when conditions change
  • Loading branch information
marySalvi authored Feb 23, 2024
2 parents b44467f + e1d41fa commit 492f894
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions web/src/use/usePaginatedResults.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
watch, Ref, computed, toRef, shallowReactive,
} from '@vue/composition-api';
import { debounce } from 'lodash';
import {
SearchParams, Condition, DataObjectFilter, SearchResponse,
} from '@/data/api';
Expand Down Expand Up @@ -40,21 +41,24 @@ export default function usePaginatedResult<T>(
});
}

const debouncedFetchResults = debounce(fetchResults, 500);

watch([
toRef(data, 'limit'),
toRef(data, 'offset'),
], fetchResults);
], debouncedFetchResults);

watch([conditions], () => {
const doFetch = data.offset === 0;
data.offset = 0;
data.limit = limit;
if (doFetch) fetchResults();
if (doFetch) debouncedFetchResults();
});

if (dataObjectFilter !== undefined) {
watch(dataObjectFilter, fetchResults, { deep: true });
watch(dataObjectFilter, debouncedFetchResults, { deep: true });
}
fetchResults();
debouncedFetchResults();
// ENDTODO

function setPage(newPage: number) {
Expand Down

0 comments on commit 492f894

Please sign in to comment.