отображение списка файлов в папках
This commit is contained in:
@ -13,7 +13,6 @@ return (
|
|||||||
<ListItem
|
<ListItem
|
||||||
onClick={() => window.router('/torrent/' + torrent.hash)}
|
onClick={() => window.router('/torrent/' + torrent.hash)}
|
||||||
primaryText={torrent.name}
|
primaryText={torrent.name}
|
||||||
secondaryText={formatBytes(torrent.size, 1)}
|
|
||||||
secondaryText={
|
secondaryText={
|
||||||
<div className='column'>
|
<div className='column'>
|
||||||
<div>
|
<div>
|
||||||
|
@ -1,20 +1,60 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import formatBytes from './format-bytes'
|
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(<ListItem
|
||||||
|
key={file}
|
||||||
|
primaryText={file}
|
||||||
|
secondaryText={formatBytes(tree[file].__sizeBT)}
|
||||||
|
nestedItems={treeToTorrentFiles(tree[file])}
|
||||||
|
primaryTogglesNestedList={true}
|
||||||
|
leftIcon={tree[file] && Object.keys(tree[file]).length > 1 ? <FileFolder /> : null}
|
||||||
|
/>);
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
const TorrentFiles = (props) => {
|
const TorrentFiles = (props) => {
|
||||||
|
let tree = buildFilesTree(props.torrent.filesList);
|
||||||
return (
|
return (
|
||||||
<div className='column'>
|
<List className='w100p'>
|
||||||
{
|
<Subheader inset={true}>Content of the torrent:</Subheader>
|
||||||
props.torrent.filesList.map((file, index) => {
|
{treeToTorrentFiles(tree)}
|
||||||
return (
|
</List>
|
||||||
<div className='row inline' key={index}>
|
|
||||||
<div>{file.path}</div>
|
|
||||||
<div style={{marginLeft: '8px'}}>({formatBytes(file.size)})</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -32,7 +72,7 @@ export default class TorrentPage extends Component {
|
|||||||
{
|
{
|
||||||
this.torrent
|
this.torrent
|
||||||
?
|
?
|
||||||
<div>
|
<div className='column w100p'>
|
||||||
{this.torrent.name}
|
{this.torrent.name}
|
||||||
<TorrentFiles torrent={this.torrent} />
|
<TorrentFiles torrent={this.torrent} />
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user