Commit 12953351 authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '45-bug-applying-filters-results-in-reload-loop' into 'main'

FIX: Applying filters results in reload loop

Closes #45

See merge request !39
parents 0180348b 34f535f5
......@@ -35,13 +35,15 @@ const DatasetListPage = ({location}: IDatasetListPageProps) => {
// state
const [datasets, setDatasets] = React.useState<FilteredPage<Dataset, DatasetFilter>>();
const [filter, setFilter] = React.useState<DatasetFilter>(appConfig.filter);
// memo
const {current, filterCode} = React.useMemo(() => parseLocationSearch(location), [location]);
const loadData = React.useCallback((filter: string | DatasetFilter, pageR: IPageRequest): Promise<FilteredPage<Dataset, DatasetFilter>> => {
return DatasetService
.datasetList(filter, pageR)
.then((data) => {
setDatasets(data);
setFilter(data.filter);
setDatasets(data);
return data;
})
.catch((e) => {
......@@ -56,11 +58,10 @@ const DatasetListPage = ({location}: IDatasetListPageProps) => {
// effect
React.useEffect(() => {
const {current, filterCode} = parseLocationSearch(location);
if (!datasets || datasets?.filterCode !== filterCode) {
loadData(filterCode || filter || datasets?.filter, current ? {page: current} : {});
}
}, [datasets, filter, loadData, location])
}, [current, filterCode])
return datasets ? (
<>
......
......@@ -37,14 +37,16 @@ const SubsetListPage = ({location}: ISubsetListPageProps) => {
const [subsets, setSubsets] = React.useState<FilteredPage<Subset, SubsetFilter>>();
const [filter, setFilter] = React.useState<SubsetFilter>(appConfig.filter as SubsetFilter);
// memo
const {current, filterCode} = React.useMemo(() => parseLocationSearch(location), [location]);
// callback
const loadData = React.useCallback((filter: string | SubsetFilter, pageR: IPageRequest): Promise<FilteredPage<Subset, SubsetFilter>> => {
return SubsetService
.list(filter, pageR)
.then((data) => {
setSubsets(data);
setFilter(data.filter);
setSubsets(data);
return data;
})
.catch((e) => {
......@@ -59,11 +61,10 @@ const SubsetListPage = ({location}: ISubsetListPageProps) => {
// effect
React.useEffect(() => {
const {current, filterCode} = parseLocationSearch(location);
if (!subsets || subsets?.filterCode !== filterCode) {
loadData(filterCode || filter || subsets?.filter, current ? {page: current} : {});
}
}, [filter, loadData, location, subsets])
}, [filterCode, current])
return subsets ? (
<>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment