Inf-scroll: Fix scroll not working when navigating back from claim.

## Fixes:
3071: "Infinite scroll stops working when navigating to file page / back"

## The Issue:
In the POP operation, the `page` value is back to 1 due to the initializer `useState(1)`. If the results cache already contained more than 1 page's worth, then the rest of the logic thinks there's nothing to do.

## The Fix:
Previous fixes to Inf-Scroll added a "page correction" code to handle the mismatch. This fix simply adds this scenario to the list of scenarios to perform the correction.
This commit is contained in:
infiinte-persistence 2020-06-23 21:08:06 +08:00 committed by Sean Yesmunt
parent ab5bd33597
commit ad37edf681

View file

@ -296,9 +296,10 @@ function ClaimListDiscover(props: Props) {
const claimSearchCacheQuery = createNormalizedClaimSearchKey(options);
const claimSearchResult = claimSearchByQuery[claimSearchCacheQuery];
const [prevOptions, setPrevOptions] = useState(options);
const [prevOptions, setPrevOptions] = useState(null);
if (!isJustScrollingToNewPage(prevOptions, options)) {
// --- New search, or search options changed.
setPrevOptions(options);
if (didNavigateForward) {
@ -306,7 +307,7 @@ function ClaimListDiscover(props: Props) {
window.scrollTo(0, 0); // Prevents onScrollBottom() from re-hitting while waiting for doClaimQuery():
options.page = 1;
setPage(options.page);
} else {
} else if (claimSearchResult) {
// --- Update 'page' based on retrieved 'claimSearchResult'.
options.page = Math.ceil(claimSearchResult.length / CS.PAGE_SIZE);
if (options.page !== page) {
@ -359,6 +360,11 @@ function ClaimListDiscover(props: Props) {
// Returns true if the change in 'options' indicate that we are simply scrolling
// down to a new page; false otherwise.
function isJustScrollingToNewPage(prevOptions, options) {
if (!prevOptions) {
// It's a new search, or we just popped back from a different view.
return false;
}
// Compare every field except for 'page' and 'release_time'.
// There might be better ways to achieve this.
let tmpPrevOptions = { ...prevOptions };