Consolidate method of reseting scroll position

## Issues
(1) 4783: New search query does not reset to the top
(2) The current way that Tag Search resets the position can be overridden by the AppRouter's call.

## Approach
Listen to `search` changes as well. This basically covers any search param changes.

Components should probably not call `window.scrollTo` directly as the AppRouter's call might override it.
This commit is contained in:
infiinte-persistence 2020-11-26 01:17:19 +08:00 committed by Sean Yesmunt
parent a23b3c8d26
commit 4b53d1267c
2 changed files with 2 additions and 3 deletions

View file

@ -347,8 +347,7 @@ function ClaimListDiscover(props: Props) {
setPrevOptions(options);
if (didNavigateForward) {
// --- Reset to top.
window.scrollTo(0, 0); // Prevents onScrollBottom() from re-hitting while waiting for doClaimQuery():
// --- Reset the page.
options.page = 1;
setPage(options.page);
} else if (claimSearchResult) {

View file

@ -179,7 +179,7 @@ function AppRouter(props: Props) {
if (!hasLinkedCommentInUrl) {
window.scrollTo(0, currentScroll);
}
}, [currentScroll, pathname, resetScroll, hasLinkedCommentInUrl]);
}, [currentScroll, pathname, search, resetScroll, hasLinkedCommentInUrl]);
// react-router doesn't decode pathanmes before doing the route matching check
// We have to redirect here because if we redirect on the server, it might get encoded again