From 81d5a367da6f1335be2f4347c2aec1431da1e8fd Mon Sep 17 00:00:00 2001 From: DC Date: Thu, 19 May 2016 00:44:59 -0700 Subject: [PATCH] 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 --- renderer/index.js | 13 ++++++++++--- renderer/views/app.js | 3 ++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/renderer/index.js b/renderer/index.js index dd35f0ef..601bc0a7 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -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) { diff --git a/renderer/views/app.js b/renderer/views/app.js index 06ac70da..a834c15b 100644 --- a/renderer/views/app.js +++ b/renderer/views/app.js @@ -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`
${error.message}
` }) return hx` -
+
Error
${errorElems}