Skip to content

Commit

Permalink
feat(gui): remember scroll on back #13
Browse files Browse the repository at this point in the history
  • Loading branch information
DEgITx committed Jul 20, 2018
1 parent 0223ad9 commit 71ce6b9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
21 changes: 21 additions & 0 deletions src/app/remember-scroll.js
Original file line number Diff line number Diff line change
@@ -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
}
}
7 changes: 5 additions & 2 deletions src/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ const history = []
let currentPage

let routers = {}
const router = (page, callback) => {
const router = (page, callback, dontClearRemember) => {
if(!callback)
{
currentPage = page ? page : '/'
if(history.length >= 10)
history.shift()
history.push(currentPage)

if(window.rememberYOffset && !dontClearRemember)
delete window.rememberYOffset

if(!page)
routers['/'].callback()
else
Expand Down Expand Up @@ -66,7 +69,7 @@ window.routerOpenPrev = () => {
if(history.length < 2)
return
history.pop() // last page
router(history.pop())
router(history.pop(), null, true)
}

window.routerFix = () => {
Expand Down
4 changes: 2 additions & 2 deletions src/app/torrent-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ export default class TorrentPage extends Page {
return (
<div className='pad1 w100p column center'>
<div className='row center pad0-75'>
<RaisedButton label={__('Back to main page')} primary={true} onClick={() => {
window.router('/')
<RaisedButton label={__('Back to previus')} primary={true} onClick={() => {
window.routerOpenPrev();
}} />
</div>
<RefreshIndicator
Expand Down
4 changes: 4 additions & 0 deletions src/app/torrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import TorrentPage from './torrent-page'

import LinearProgress from 'material-ui/LinearProgress';
let rating = require('./rating');
import scrollBack from './remember-scroll'

const contentIcon = (type, category, fill = 'grey') => {
if(category == 'xxx')
Expand Down Expand Up @@ -186,6 +187,8 @@ export default class Torrent extends Component {

componentDidMount()
{
scrollBack()

this.downloading = (hash) => {
if(this.props.torrent.hash != hash)
return;
Expand Down Expand Up @@ -272,6 +275,7 @@ export default class Torrent extends Component {
return true;
}
*/
window.rememberYOffset = window.pageYOffset
window.routerFix()
PagesPie.instance().open(TorrentPage, {replace: 'all', hash: torrent.hash, peer: torrent.peer})
}}
Expand Down

0 comments on commit 71ce6b9

Please sign in to comment.