Skip to content

Commit

Permalink
client: Scroll to top on page change
Browse files Browse the repository at this point in the history
  • Loading branch information
jtojnar committed Jan 26, 2021
1 parent 7a17646 commit 2923c90
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions assets/js/templates/EntriesPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2923c90

Please sign in to comment.