receptor/src/ui/torrent_table.js

57 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-08-22 21:49:48 +02:00
import React, { Component } from 'react';
import { connect } from 'react-redux';
2017-08-23 14:52:08 +02:00
function formatBitrate(bitrate) {
if (bitrate > 1000000000) {
return `${(bitrate / 1000000000).toFixed(2)} Gb/s`;
} else if (bitrate > 1000000) {
return `${(bitrate / 1000000).toFixed(2)} Mb/s`;
} else if (bitrate > 1000) {
return `${(bitrate / 1000).toFixed(2)} Kb/s`;
} else {
return `${bitrate} b/s`;
}
}
2017-08-22 21:49:48 +02:00
class TorrentTable extends Component {
render() {
const { torrents } = this.props;
return (
<table className="table">
<thead>
<tr>
2017-08-23 14:42:00 +02:00
<th style={{width: "1px"}}></th>
2017-08-22 21:49:48 +02:00
<th>name</th>
<th>up</th>
<th>down</th>
</tr>
</thead>
<tbody>
{Object.values(torrents).map(t =>
<tr
key={t.id}
2017-08-23 14:42:00 +02:00
className={`torrent ${t.status}`}
2017-08-22 21:49:48 +02:00
style={{
2017-08-23 14:27:08 +02:00
backgroundSize: `${t.progress * 100}% 3px`
2017-08-22 21:49:48 +02:00
}}
>
2017-08-23 14:42:00 +02:00
<td>
<input type="checkbox" />
</td>
2017-08-22 21:49:48 +02:00
<td>
<a href="#">
{t.name}
</a>
</td>
2017-08-23 14:52:08 +02:00
<td>{formatBitrate(t.rate_up)}</td>
<td>{formatBitrate(t.rate_down)}</td>
2017-08-22 21:49:48 +02:00
</tr>
)}
</tbody>
</table>
);
}
}
export default connect(state => ({ torrents: state.torrents }))(TorrentTable);