From ad37edf6814b4fb61c17e8313eae2027eef0a459 Mon Sep 17 00:00:00 2001 From: infiinte-persistence Date: Tue, 23 Jun 2020 21:08:06 +0800 Subject: [PATCH] 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. --- ui/component/claimListDiscover/view.jsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ui/component/claimListDiscover/view.jsx b/ui/component/claimListDiscover/view.jsx index 4c427e050..54869502c 100644 --- a/ui/component/claimListDiscover/view.jsx +++ b/ui/component/claimListDiscover/view.jsx @@ -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 };