From 52b404b552038da52096268c71e6a82840509126 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Thu, 6 Jul 2017 04:14:45 +0100 Subject: [PATCH] Issue #312 home page scroll position on back navigation --- ui/js/page/discover/view.jsx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/ui/js/page/discover/view.jsx b/ui/js/page/discover/view.jsx index d6c506dfd..99387949d 100644 --- a/ui/js/page/discover/view.jsx +++ b/ui/js/page/discover/view.jsx @@ -3,6 +3,7 @@ import lbryio from "lbryio.js"; import lbryuri from "lbryuri"; import FileCard from "component/fileCard"; import { BusyMessage } from "component/common.js"; +import { setSession, getSession } from "utils"; import ToolTip from "component/tooltip.js"; const FeaturedCategory = props => { @@ -37,10 +38,27 @@ const FeaturedCategory = props => { class DiscoverPage extends React.PureComponent { componentWillMount() { 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() { this.props.cancelResolvingUris(); + window.removeEventListener("scroll", this.scrollListener); } render() { @@ -51,7 +69,7 @@ class DiscoverPage extends React.PureComponent { (featuredUris !== undefined && Object.keys(featuredUris).length === 0)); return ( -
+
{fetchingFeaturedUris && } {typeof featuredUris === "object" &&