Issue #312 home page scroll position on back navigation

This commit is contained in:
Akinwale Ariwodola 2017-07-06 04:14:45 +01:00
parent 48c10b6c53
commit 52b404b552

View file

@ -3,6 +3,7 @@ import lbryio from "lbryio.js";
import lbryuri from "lbryuri"; import lbryuri from "lbryuri";
import FileCard from "component/fileCard"; import FileCard from "component/fileCard";
import { BusyMessage } from "component/common.js"; import { BusyMessage } from "component/common.js";
import { setSession, getSession } from "utils";
import ToolTip from "component/tooltip.js"; import ToolTip from "component/tooltip.js";
const FeaturedCategory = props => { const FeaturedCategory = props => {
@ -37,10 +38,27 @@ const FeaturedCategory = props => {
class DiscoverPage extends React.PureComponent { class DiscoverPage extends React.PureComponent {
componentWillMount() { componentWillMount() {
this.props.fetchFeaturedUris(); this.props.fetchFeaturedUris();
this.scrollListener = this.handleScroll.bind(this);
}
componentDidMount() {
const scrollY = parseInt(getSession("prefs_scrolly"));
if (!isNaN(scrollY)) {
const restoreScrollPosition = () => {
window.scrollTo(0, scrollY);
};
setTimeout(restoreScrollPosition, 100);
}
window.addEventListener("scroll", this.scrollListener);
}
handleScroll() {
setSession("prefs_scrolly", window.scrollY);
} }
componentWillUnmount() { componentWillUnmount() {
this.props.cancelResolvingUris(); this.props.cancelResolvingUris();
window.removeEventListener("scroll", this.scrollListener);
} }
render() { render() {
@ -51,7 +69,7 @@ class DiscoverPage extends React.PureComponent {
(featuredUris !== undefined && Object.keys(featuredUris).length === 0)); (featuredUris !== undefined && Object.keys(featuredUris).length === 0));
return ( return (
<main> <main ref="main">
{fetchingFeaturedUris && {fetchingFeaturedUris &&
<BusyMessage message={__("Fetching content")} />} <BusyMessage message={__("Fetching content")} />}
{typeof featuredUris === "object" && {typeof featuredUris === "object" &&