отображение списка файлов
This commit is contained in:
parent
6fc2d2efb4
commit
e71cf5f1bf
8
src/format-bytes.js
Normal file
8
src/format-bytes.js
Normal 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];
|
||||||
|
}
|
@ -23,7 +23,7 @@ export default class RecentTorrents extends Component {
|
|||||||
{
|
{
|
||||||
this.torrents.map((torrent, index) =>{
|
this.torrents.map((torrent, index) =>{
|
||||||
return(
|
return(
|
||||||
<div key={index}>
|
<div key={index} className='clickable' onClick={() => window.router('/torrent/' + torrent.hash)}>
|
||||||
{torrent.name}
|
{torrent.name}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -1,4 +1,22 @@
|
|||||||
import React, { Component } from 'react';
|
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 {
|
export default class TorrentPage extends Component {
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -16,6 +34,7 @@ export default class TorrentPage extends Component {
|
|||||||
?
|
?
|
||||||
<div>
|
<div>
|
||||||
{this.torrent.name}
|
{this.torrent.name}
|
||||||
|
<TorrentFiles torrent={this.torrent} />
|
||||||
</div>
|
</div>
|
||||||
:
|
:
|
||||||
null
|
null
|
||||||
|
Loading…
Reference in New Issue
Block a user