From ef705211ab7f3cdc81d0f89c65d48163fac4c360 Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Fri, 9 Feb 2018 10:07:25 +0300 Subject: [PATCH] fix(download): cancel controls on torrent element --- src/app/torrent-page.js | 2 +- src/app/torrent.js | 25 +++++++++++++++++++++---- src/background/spider.js | 6 ++++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/app/torrent-page.js b/src/app/torrent-page.js index e29b7bf..59975c7 100644 --- a/src/app/torrent-page.js +++ b/src/app/torrent-page.js @@ -404,7 +404,7 @@ export default class TorrentPage extends Page { { diff --git a/src/app/torrent.js b/src/app/torrent.js index c319113..faeb00c 100644 --- a/src/app/torrent.js +++ b/src/app/torrent.js @@ -169,11 +169,14 @@ export default class Torrent extends Component { } window.torrentSocket.on('downloading', this.downloading); - this.downloadDone = (hash) => { + this.downloadDone = (hash, canceled) => { if(this.props.torrent.hash != hash) return; - this.setState({downloading: false}) + this.setState({ + downloading: false, + askDownloading: !canceled + }) } window.torrentSocket.on('downloadDone', this.downloadDone); @@ -246,7 +249,7 @@ export default class Torrent extends Component { } @@ -312,8 +315,22 @@ export default class Torrent extends Component { : this.state.askDownloading && !this.state.downloading - && + ? + : + this.state.askDownloading && this.state.downloading + && + + { + e.preventDefault(); + e.stopPropagation(); + + window.torrentSocket.emit('downloadCancel', torrent.hash) + }} viewBox="0 0 18 18"> + } { const id = torrentClientHashMap[hash] if(!id) { - callback(false) + if(callback) + callback(false) return } torrentClient.remove(id, (err) => { if(err) { - callback(false) + if(callback) + callback(false) return }