diff --git a/client/source/scripts/components/torrent-list/Torrent.js b/client/source/scripts/components/torrent-list/Torrent.js index 38f83770..08e1b249 100644 --- a/client/source/scripts/components/torrent-list/Torrent.js +++ b/client/source/scripts/components/torrent-list/Torrent.js @@ -20,87 +20,6 @@ export default class Torrent extends React.Component { }); } - getEta(eta) { - if (eta === 'Infinity') { - return '∞'; - } else if (eta.years > 0) { - return ( - - - {eta.years}yr - - - {eta.weeks}wk - - - ); - } else if (eta.weeks > 0) { - return ( - - - - {eta.weeks}wk - - - {eta.days}d - - - ); - } else if (eta.days > 0) { - return ( - - - {eta.days}d - - - {eta.hours}hr - - - ); - } else if (eta.hours > 0) { - return ( - - - {eta.hours}hr - - - {eta.minutes}m - - - ); - } else if (eta.minutes > 0) { - return ( - - - {eta.minutes}m - - - {eta.seconds}s - - - ); - } else { - return ( - - {eta.seconds}s - - ); - } - } - - getRatio(ratio) { - ratio = ratio / 1000; - let precision = 1; - - if (ratio < 10) { - precision = 2; - } else if (ratio < 100) { - precision = 0; - } - - return ratio.toFixed(precision); - } - handleClick(event) { this.props.handleClick(this.props.data.hash, event); } @@ -117,8 +36,8 @@ export default class Torrent extends React.Component { let completed = format.data(torrent.bytesDone); let downloadRate = format.data(torrent.downloadRate, '/s'); let downloadTotal = format.data(torrent.downloadTotal); - let eta = this.getEta(torrent.eta); - let ratio = this.getRatio(torrent.ratio); + let eta = format.eta(torrent.eta); + let ratio = format.ratio(torrent.ratio); let totalSize = format.data(torrent.sizeBytes); let uploadRate = format.data(torrent.uploadRate, '/s'); let uploadTotal = format.data(torrent.uploadTotal); diff --git a/client/source/scripts/components/torrent-list/TorrentDetails.js b/client/source/scripts/components/torrent-list/TorrentDetails.js index 520d7dec..36107862 100644 --- a/client/source/scripts/components/torrent-list/TorrentDetails.js +++ b/client/source/scripts/components/torrent-list/TorrentDetails.js @@ -9,9 +9,9 @@ import Icon from '../icons/Icon'; import clientSelector from '../../selectors/clientSelector'; const methodsToBind = [ - 'getSidePanel', - 'getEta', - 'getRatio' + 'getFileData', + 'getHeading', + 'getSidePanel' ]; class TorrentDetails extends React.Component { @@ -31,35 +31,88 @@ class TorrentDetails extends React.Component { componentWillReceiveProps(nextProps) { if (nextProps.visible === true) { let nextHash = nextProps.selectedTorrents[0]; - if (this.state.selectedTorrentHash !== nextHash) { - this.setState({ - selectedTorrentHash: nextHash, - selectedTorrent: _.find(nextProps.torrents, torrent => { - return torrent.hash === nextHash; - }) - }); - } + this.setState({ + selectedTorrentHash: nextHash, + selectedTorrent: _.find(nextProps.torrents, torrent => { + return torrent.hash === nextHash; + }) + }); } } shouldComponentUpdate(nextProps) { - if (nextProps.visible === true || (nextProps.visible !== this.props.visible)) { + if (this.props.visible === true || (nextProps.visible !== this.props.visible)) { return true; } else { return false; } } - getPeerList() { - let torrentDetails = this.props.torrentDetails[ - this.state.selectedTorrentHash - ]; + getFileData(torrent, files) { + let parentDirectory = torrent.directory; + let filename = torrent.filename; - let peerList = null; - let peerCount = 0; + if (parentDirectory.endsWith(torrent.filename)) { + parentDirectory = parentDirectory.substring( + 0, parentDirectory.length - torrent.filename.length + ); + } - if (torrentDetails) { - peerList = torrentDetails.map(function(peer, index) { + if (parentDirectory.endsWith('/') || parentDirectory.endsWith('\\')) { + parentDirectory = parentDirectory.substr( + 0, parentDirectory.length - 1 + ); + } + + if (files) { + let fileList = files.map(pathItem => { + let classes = classNames({ + 'torrent-details__file-data__filename': true, + [`torrent-details__file-data__depth--${pathItem.pathDepth}`]: pathItem.pathDepth > 0 + }); + return ( +
+ {pathItem.path} +
+ ); + }); + return ( +
+
+ {parentDirectory} +
+ {fileList} +
+ ); + } else { + return ( +
+
+ {parentDirectory} +
+
+ {filename} +
+
+ ); + } + } + + getHeading() { + // return ( + //
+ // Dropdown + //
+ // ); + } + + getPeerList(peers) { + if (peers) { + let peerList = null; + let peerCount = 0; + + peerList = peers.map(function(peer, index) { let downloadRate = format.data(peer.downloadRate, '/s'); let uploadRate = format.data(peer.uploadRate, '/s'); return ( @@ -77,107 +130,29 @@ class TorrentDetails extends React.Component { ); }); peerCount = peerList.length; + + return ( +
+ + + + + + + + + + {peerList} + +
+ Peers + + {peerCount} + + DLUL
+
+ ) } - - return ( - - - - - - - - - - {peerList} - -
- Peers - - {peerCount} - - DLUL
- ) - } - - getEta(eta) { - if (eta === 'Infinity') { - return '∞'; - } else if (eta.years > 0) { - return ( - - - {eta.years}yr - - - {eta.weeks}wk - - - ); - } else if (eta.weeks > 0) { - return ( - - - {eta.weeks}wk - - - {eta.days}d - - - ); - } else if (eta.days > 0) { - return ( - - - {eta.days}d - - - {eta.hours}hr - - - ); - } else if (eta.hours > 0) { - return ( - - - {eta.hours}hr - - - {eta.minutes}m - - - ); - } else if (eta.minutes > 0) { - return ( - - - {eta.minutes}m - - - {eta.seconds}s - - - ); - } else { - return ( - - {eta.seconds}s - - ); - } - } - - getRatio(ratio) { - ratio = ratio / 1000; - let precision = 1; - - if (ratio < 10) { - precision = 2; - } else if (ratio < 100) { - precision = 0; - } - - return ratio.toFixed(precision); } getSidePanel() { @@ -192,18 +167,19 @@ class TorrentDetails extends React.Component { let completed = format.data(torrent.bytesDone); let downloadRate = format.data(torrent.downloadRate, '/s'); let downloadTotal = format.data(torrent.downloadTotal); - let eta = this.getEta(torrent.eta); - let ratio = this.getRatio(torrent.ratio); + let eta = format.eta(torrent.eta); + let ratio = format.ratio(torrent.ratio); let totalSize = format.data(torrent.sizeBytes); + let torrentDetails = this.props.torrentDetails[ + this.state.selectedTorrentHash + ] || {}; let uploadRate = format.data(torrent.uploadRate, '/s'); let uploadTotal = format.data(torrent.uploadTotal); return (
-
- Dropdown -
-
); }