diff --git a/src/format-bytes.js b/src/format-bytes.js new file mode 100644 index 0000000..d902356 --- /dev/null +++ b/src/format-bytes.js @@ -0,0 +1,8 @@ +export default function formatBytes(bytes,decimals) { + if(bytes == 0) return '0 Byte'; + var k = 1000; // or 1024 for binary + var dm = decimals + 1 || 3; + var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + var i = Math.floor(Math.log(bytes) / Math.log(k)); + return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; +} \ No newline at end of file diff --git a/src/recent-torrents.js b/src/recent-torrents.js index a5dbe42..0dcbe63 100644 --- a/src/recent-torrents.js +++ b/src/recent-torrents.js @@ -23,7 +23,7 @@ export default class RecentTorrents extends Component { { this.torrents.map((torrent, index) =>{ return( -
+
window.router('/torrent/' + torrent.hash)}> {torrent.name}
); diff --git a/src/torrent-page.js b/src/torrent-page.js index d69637d..d4a9068 100644 --- a/src/torrent-page.js +++ b/src/torrent-page.js @@ -1,4 +1,22 @@ import React, { Component } from 'react'; +import formatBytes from './format-bytes' + +const TorrentFiles = (props) => { + return ( +
+ { + props.torrent.filesList.map((file, index) => { + return ( +
+
{file.path}
+
({formatBytes(file.size)})
+
+ ); + }) + } +
+ ); +}; export default class TorrentPage extends Component { componentDidMount() { @@ -16,6 +34,7 @@ export default class TorrentPage extends Component { ?
{this.torrent.name} +
: null