From 2923c90aa88ba0b22871fe27ddfbc4210b6c022b Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Tue, 19 Jan 2021 18:21:27 +0100 Subject: [PATCH] client: Scroll to top on page change --- assets/js/templates/EntriesPage.jsx | 39 ++++++++++++++++------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/assets/js/templates/EntriesPage.jsx b/assets/js/templates/EntriesPage.jsx index 53b67781ea..b5c3108930 100644 --- a/assets/js/templates/EntriesPage.jsx +++ b/assets/js/templates/EntriesPage.jsx @@ -45,27 +45,30 @@ function reloadList({ fetchParams, append = false, waitForSync = true, entryId = } else { selfoss.entriesPage.setExpandedEntries({}); selfoss.entriesPage.setEntries(entries); - } - - // open selected entry only if entry was requested (i.e. if not streaming - // more) - if (entryId && fetchParams.fromId === undefined) { - var entry = document.querySelector(`.entry[data-entry-id="${entryId}"]`); - - if (!entry) { - return; - } - selfoss.ui.entryActivate(entryId); - // ensure scrolling to requested entry even if scrolling to article - // header is disabled - if (!selfoss.config.scrollToArticleHeader) { - // needs to be delayed for some reason - requestAnimationFrame(() => { - entry.scrollIntoView(); - }); + // open selected entry only if entry was requested (i.e. if not streaming + // more) + if (entryId && fetchParams.fromId === undefined) { + var entry = document.querySelector(`.entry[data-entry-id="${entryId}"]`); + + if (!entry) { + return; + } + + selfoss.ui.entryActivate(entryId); + // ensure scrolling to requested entry even if scrolling to article + // header is disabled + if (!selfoss.config.scrollToArticleHeader) { + // needs to be delayed for some reason + requestAnimationFrame(() => { + entry.scrollIntoView(); + }); + } + } else { + window.scrollTo({ top: 0 }); } } + }).catch((error) => { setLoadingState(LoadingState.FAILURE); selfoss.ui.showError(selfoss.ui._('error_loading') + ' ' + error.message);