From 354cb5afd4cbc7c274240167c7353b98b02351d8 Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Thu, 19 Jan 2017 19:52:21 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B1=D0=BE=D0=BB=D0=B5=D0=B5=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=D0=BA=D0=B8=D0=B9=20=D0=B2=D1=8B=D0=B7=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/recent-torrents.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/recent-torrents.js b/src/recent-torrents.js index 0547a47..f2a8223 100644 --- a/src/recent-torrents.js +++ b/src/recent-torrents.js @@ -167,9 +167,11 @@ export default class RecentTorrents extends Component { constructor() { super() this.torrents = []; + this.torrentsAssoc = {}; this.displayQueue = []; this.displayQueueAssoc = {}; - this.maxDisplaySize = 1000; + this.maxQueueSize = 1000; + this.maxDisplaySize = 10; this.state = { pause: false, searchingIndicator: false @@ -201,15 +203,26 @@ export default class RecentTorrents extends Component { let torrent = this.displayQueue.shift(); this.torrents.unshift(torrent); - if(this.torrents.length > 10) { + this.torrentsAssoc[torrent.hash] = torrent; + if(this.torrents.length > this.maxDisplaySize) { let toDelete = this.torrents.pop() + delete this.torrentsAssoc[toDelete.hash]; delete this.displayQueueAssoc[toDelete.hash]; } + this.displayTorrentCounterValue = this.displayQueue.length; this.forceUpdate(); setTimeout(this.displayNewTorrent, speed); } this.displayNewTorrent(); + + this.displayTorrentCounterValue = 0; + this.displayTorrentCounter = setInterval(() => { + if(this.displayTorrentCounterValue != this.displayQueue.length) { + this.displayTorrentCounterValue = this.displayQueue.length; + this.forceUpdate(); + } + }, 40); }, () => { this.setState({ searchingIndicator: true @@ -220,10 +233,9 @@ export default class RecentTorrents extends Component { }); })); this.newTorrentFunc = (torrent) => { - if(this.displayQueue.length < this.maxDisplaySize) { + if(this.displayQueue.length < this.maxQueueSize) { this.displayQueue.push(torrent); this.displayQueueAssoc[torrent.hash] = torrent; - this.forceUpdate(); } }; window.torrentSocket.on('newTorrent', this.newTorrentFunc); @@ -232,7 +244,9 @@ export default class RecentTorrents extends Component { if(statistic.hash in this.displayQueueAssoc) { Object.assign(this.displayQueueAssoc[statistic.hash], statistic); - this.forceUpdate(); + if(statistic.hash in this.torrentsAssoc) { + this.forceUpdate(); + } } } window.torrentSocket.on('trackerTorrentUpdate', this.tracketUpdate); @@ -249,6 +263,8 @@ export default class RecentTorrents extends Component { window.torrentSocket.off('trackerTorrentUpdate', this.tracketUpdate); if(this.displayNewTorrent) delete this.displayNewTorrent; + if(this.displayTorrentCounter) + clearInterval(this.displayTorrentCounter); } render() { const style = {