Add new torrents to top and scroll to top

This means people who add a lot of torrents will always have their latest torrents at the top when they open the app, instead of having to scroll all the way down
This commit is contained in:
DC
2016-05-19 00:44:59 -07:00
parent 189e4bdc24
commit 81d5a367da
2 changed files with 12 additions and 4 deletions

View File

@@ -213,6 +213,7 @@ function dispatch (action, ...args) {
onOpen(args[0] /* files */)
}
if (action === 'addTorrent') {
backToList()
addTorrent(args[0] /* torrent */)
}
if (action === 'showOpenTorrentFile') {
@@ -427,11 +428,16 @@ function openSubtitles () {
})
}
// Quits any modal popovers and returns to the torrent list screen
function backToList () {
// Exit any modals and screens with a back button
state.modal = null
while (state.location.hasBack()) state.location.back()
// If we were already on the torrent list, scroll to the top
var contentTag = document.querySelector('.content')
if (contentTag) contentTag.scrollTop = 0
// Work around virtual-dom issue: it doesn't expose its redraw function,
// and only redraws on requestAnimationFrame(). That means when the user
// closes the window (hide window / minimize to tray) and we want to pause
@@ -555,7 +561,6 @@ function onOpen (files) {
if (!Array.isArray(files)) files = [ files ]
// Return to the home screen
state.modal = null
backToList()
if (files.every(isTorrent)) {
@@ -814,7 +819,7 @@ function torrentInfoHash (torrentKey, infoHash) {
torrentKey: torrentKey,
status: 'new'
}
state.saved.torrents.push(torrentSummary)
state.saved.torrents.unshift(torrentSummary)
sound.play('ADD')
}
@@ -1266,8 +1271,10 @@ function onPaste (e) {
torrentIds.forEach(function (torrentId) {
torrentId = torrentId.trim()
if (torrentId.length === 0) return
dispatch('addTorrent', torrentId)
addTorrent(torrentId)
})
update()
}
function onFocus (e) {

View File

@@ -54,12 +54,13 @@ function App (state) {
function getErrorPopover (state) {
var now = new Date().getTime()
var recentErrors = state.errors.filter((x) => now - x.time < 5000)
var hasErrors = recentErrors.length > 0
var errorElems = recentErrors.map(function (error) {
return hx`<div class='error'>${error.message}</div>`
})
return hx`
<div class='error-popover ${recentErrors.length > 0 ? 'visible' : 'hidden'}'>
<div class='error-popover ${hasErrors ? 'visible' : 'hidden'}'>
<div class='title'>Error</div>
${errorElems}
</div>