diff --git a/src/recent-torrents.js b/src/recent-torrents.js index c3364b1..79cbaf1 100644 --- a/src/recent-torrents.js +++ b/src/recent-torrents.js @@ -13,7 +13,6 @@ return ( window.router('/torrent/' + torrent.hash)} primaryText={torrent.name} - secondaryText={formatBytes(torrent.size, 1)} secondaryText={
diff --git a/src/torrent-page.js b/src/torrent-page.js index d4a9068..dc4a002 100644 --- a/src/torrent-page.js +++ b/src/torrent-page.js @@ -1,20 +1,60 @@ import React, { Component } from 'react'; import formatBytes from './format-bytes' +import {List, ListItem} from 'material-ui/List'; +import Subheader from 'material-ui/Subheader'; +import Divider from 'material-ui/Divider'; + +import FileFolder from 'material-ui/svg-icons/file/folder'; + +let buildFilesTree = (filesList) => { + let rootTree = { + __sizeBT: 0 + }; + filesList.forEach((file) => { + let pathTree = file.path.split('/'); + let currentItem = rootTree; + pathTree.forEach((pathItem) => { + if(!(pathItem in currentItem)) + { + currentItem[pathItem] = { + __sizeBT: 0 + } + } + currentItem = currentItem[pathItem] + currentItem.__sizeBT += file.size; + }) + rootTree.__sizeBT += file.size; + }); + return rootTree; +} + +const treeToTorrentFiles = (tree) => { + let arr = []; + for(let file in tree) + { + if(file == '__sizeBT') + continue; + + arr.push( 1 ? : null} + />); + } + return arr; +} + const TorrentFiles = (props) => { + let tree = buildFilesTree(props.torrent.filesList); return ( -
- { - props.torrent.filesList.map((file, index) => { - return ( -
-
{file.path}
-
({formatBytes(file.size)})
-
- ); - }) - } -
+ + Content of the torrent: + {treeToTorrentFiles(tree)} + ); }; @@ -32,7 +72,7 @@ export default class TorrentPage extends Component { { this.torrent ? -
+
{this.torrent.name}