Skip to content

Commit

Permalink
fix(connectInfiniteHits): fix state when navigating or adding/removin…
Browse files Browse the repository at this point in the history
…g widgets (#4123)
  • Loading branch information
Yannick Croissant authored Sep 19, 2019
1 parent 531bbe8 commit 9605230
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/connectors/infinite-hits/connectInfiniteHits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,16 @@ const connectInfiniteHits: InfiniteHitsConnector = (
// if we only change pages.
const {
page = 0,
facets,
hierarchicalFacets,
disjunctiveFacets,
maxValuesPerFacet,
...currentState
} = state;

currentState.facetsRefinements = filterEmptyRefinements(
currentState.facetsRefinements
);
currentState.hierarchicalFacetsRefinements = filterEmptyRefinements(
currentState.hierarchicalFacetsRefinements
);
Expand Down Expand Up @@ -242,20 +247,11 @@ const connectInfiniteHits: InfiniteHitsConnector = (
);
}

if (!hasShowPrevious) {
return widgetSearchParameters;
}

if (uiState.page) {
// The page in the search parameters is decremented by one
// to get to the actual parameter value from the UI state.
return widgetSearchParameters.setQueryParameter(
'page',
uiState.page - 1
);
}
// The page in the search parameters is decremented by one
// to get to the actual parameter value from the UI state.
const page = uiState.page ? uiState.page - 1 : 0;

return widgetSearchParameters.setQueryParameter('page', 0);
return widgetSearchParameters.setQueryParameter('page', page);
},
};
};
Expand Down

0 comments on commit 9605230

Please sign in to comment.