diff --git a/src/app/torrent.js b/src/app/torrent.js index 6cc0618..edbe73d 100644 --- a/src/app/torrent.js +++ b/src/app/torrent.js @@ -161,20 +161,26 @@ export default class Torrent extends Component { downloading: false, downloaded: false, startingDownloading: false, - downloadProgress: {} + downloadProgress: {}, + downloadRemoveOnDone: false } constructor(props) { super(props) - if(props.download) + + const download = props.download || props.torrent.download + if(download) { - const { progress, downloaded, downloadSpeed } = props.download + const { progress, downloaded, downloadSpeed, removeOnDone } = download this.state.downloadProgress = { progress, downloaded, downloadSpeed } - this.state.downloading = true + this.state.downloading = progress < 1 + this.state.downloaded = progress === 1 + this.state.downloadRemoveOnDone = removeOnDone } } + componentDidMount() { this.downloading = (hash) => { @@ -211,6 +217,16 @@ export default class Torrent extends Component { }) } window.torrentSocket.on('downloadProgress', this.downloadProgress); + + this.downloadUpdate = (hash, options) => { + if(this.props.torrent.hash != hash) + return; + + this.setState({ + downloadRemoveOnDone: options.removeOnDone + }) + } + window.torrentSocket.on('downloadUpdate', this.downloadUpdate); } componentWillUnmount() { @@ -220,6 +236,8 @@ export default class Torrent extends Component { window.torrentSocket.off('downloadDone', this.downloadDone); if(this.downloadProgress) window.torrentSocket.off('downloadProgress', this.downloadProgress); + if(this.downloadUpdate) + window.torrentSocket.off('downloadUpdate', this.downloadUpdate); } render() { @@ -231,6 +249,8 @@ export default class Torrent extends Component { if(torrent.good > 0 || torrent.bad > 0) torrentRating = Math.round(rating(torrent.good, torrent.bad) * 100); + const canDeleteDownloadAfterFinish = (this.state.downloading || this.state.startingDownloading) && !this.state.downloaded + return (