feat(gui): remember scroll on back #13

This commit is contained in:
Alexey Kasyanchuk 2018-07-20 13:08:30 +03:00
parent 454d65d623
commit 246a7a9797
4 changed files with 32 additions and 4 deletions

View File

@ -0,0 +1,21 @@
let scrollLock = false
export default () => {
if(scrollLock)
return
scrollLock = true
// set scroll to prev position
if(window.rememberYOffset)
{
console.log('scroll back')
setTimeout(() => {
window.scrollTo(0, window.rememberYOffset + (window.rememberYOffset > 15 ? 330 : 0))
delete window.rememberYOffset
scrollLock = false
}, 10);
}
else
{
scrollLock = false
}
}

View File

@ -16,7 +16,7 @@ const history = []
let currentPage let currentPage
let routers = {} let routers = {}
const router = (page, callback) => { const router = (page, callback, dontClearRemember) => {
if(!callback) if(!callback)
{ {
currentPage = page ? page : '/' currentPage = page ? page : '/'
@ -24,6 +24,9 @@ const router = (page, callback) => {
history.shift() history.shift()
history.push(currentPage) history.push(currentPage)
if(window.rememberYOffset && !dontClearRemember)
delete window.rememberYOffset
if(!page) if(!page)
routers['/'].callback() routers['/'].callback()
else else
@ -66,7 +69,7 @@ window.routerOpenPrev = () => {
if(history.length < 2) if(history.length < 2)
return return
history.pop() // last page history.pop() // last page
router(history.pop()) router(history.pop(), null, true)
} }
window.routerFix = () => { window.routerFix = () => {

View File

@ -319,8 +319,8 @@ export default class TorrentPage extends Page {
return ( return (
<div className='pad1 w100p column center'> <div className='pad1 w100p column center'>
<div className='row center pad0-75'> <div className='row center pad0-75'>
<RaisedButton label={__('Back to main page')} primary={true} onClick={() => { <RaisedButton label={__('Back to previus')} primary={true} onClick={() => {
window.router('/') window.routerOpenPrev();
}} /> }} />
</div> </div>
<RefreshIndicator <RefreshIndicator

View File

@ -9,6 +9,7 @@ import TorrentPage from './torrent-page'
import LinearProgress from 'material-ui/LinearProgress'; import LinearProgress from 'material-ui/LinearProgress';
let rating = require('./rating'); let rating = require('./rating');
import scrollBack from './remember-scroll'
const contentIcon = (type, category, fill = 'grey') => { const contentIcon = (type, category, fill = 'grey') => {
if(category == 'xxx') if(category == 'xxx')
@ -186,6 +187,8 @@ export default class Torrent extends Component {
componentDidMount() componentDidMount()
{ {
scrollBack()
this.downloading = (hash) => { this.downloading = (hash) => {
if(this.props.torrent.hash != hash) if(this.props.torrent.hash != hash)
return; return;
@ -272,6 +275,7 @@ export default class Torrent extends Component {
return true; return true;
} }
*/ */
window.rememberYOffset = window.pageYOffset
window.routerFix() window.routerFix()
PagesPie.instance().open(TorrentPage, {replace: 'all', hash: torrent.hash, peer: torrent.peer}) PagesPie.instance().open(TorrentPage, {replace: 'all', hash: torrent.hash, peer: torrent.peer})
}} }}