receptor/src/ui/torrent_table.js

67 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-08-22 21:49:48 +02:00
import React, { Component } from 'react';
import { connect } from 'react-redux';
import selectTorrent, { UNION, SUBTRACT, EXCLUSIVE } from '../actions/selection';
2017-08-25 04:49:24 +02:00
import { formatBitrate } from '../bitrate';
2017-08-23 14:52:08 +02:00
2017-08-22 21:49:48 +02:00
class TorrentTable extends Component {
render() {
const { selection, torrents, dispatch } = this.props;
2017-08-22 21:49:48 +02:00
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>
2017-08-25 02:01:15 +02:00
<th>ratio</th>
2017-08-22 21:49:48 +02:00
</tr>
</thead>
<tbody>
{Object.values(torrents).map(t =>
<tr
key={t.id}
2017-08-25 04:32:42 +02:00
className={`torrent progress-row ${
2017-08-25 02:01:15 +02:00
t.status
} ${
selection.indexOf(t.id) !== -1 ? "selected" : ""
2017-08-25 02:01:15 +02:00
}`}
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>
2017-08-25 02:01:15 +02:00
<input
type="checkbox"
checked={selection.indexOf(t.id) !== -1}
2017-08-25 02:01:15 +02:00
onChange={e =>
dispatch(selectTorrent(t.id, e.target.checked ? UNION : SUBTRACT))
}
2017-08-25 02:01:15 +02:00
/>
2017-08-23 14:42:00 +02:00
</td>
2017-08-22 21:49:48 +02:00
<td>
2017-08-25 02:01:15 +02:00
<a
href={`/torrents/${t.id}`}
2017-08-25 02:01:15 +02:00
onClick={e => {
e.preventDefault();
dispatch(selectTorrent(t.id, EXCLUSIVE));
2017-08-25 02:01:15 +02:00
}}
>{t.name}</a>
2017-08-22 21:49:48 +02:00
</td>
2017-08-23 14:52:08 +02:00
<td>{formatBitrate(t.rate_up)}</td>
<td>{formatBitrate(t.rate_down)}</td>
2017-08-25 02:01:15 +02:00
<td>{(t.transferred_up / t.transferred_down).toFixed(2)}</td>
2017-08-22 21:49:48 +02:00
</tr>
)}
</tbody>
</table>
);
}
}
2017-08-25 02:01:15 +02:00
export default connect(state => ({
torrents: state.torrents,
selection: state.selection,
2017-08-25 02:01:15 +02:00
router: state.router
}))(TorrentTable);