отображение списка файлов

This commit is contained in:
Alexey Kasyanchuk 2017-01-01 10:06:08 +03:00
parent 6fc2d2efb4
commit e71cf5f1bf
3 changed files with 28 additions and 1 deletions

8
src/format-bytes.js Normal file
View File

@ -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];
}

View File

@ -23,7 +23,7 @@ export default class RecentTorrents extends Component {
{
this.torrents.map((torrent, index) =>{
return(
<div key={index}>
<div key={index} className='clickable' onClick={() => window.router('/torrent/' + torrent.hash)}>
{torrent.name}
</div>
);

View File

@ -1,4 +1,22 @@
import React, { Component } from 'react';
import formatBytes from './format-bytes'
const TorrentFiles = (props) => {
return (
<div className='column'>
{
props.torrent.filesList.map((file, index) => {
return (
<div className='row inline' key={index}>
<div>{file.path}</div>
<div style={{marginLeft: '8px'}}>({formatBytes(file.size)})</div>
</div>
);
})
}
</div>
);
};
export default class TorrentPage extends Component {
componentDidMount() {
@ -16,6 +34,7 @@ export default class TorrentPage extends Component {
?
<div>
{this.torrent.name}
<TorrentFiles torrent={this.torrent} />
</div>
:
null