receptor/src/ui/torrent_table.js

80 lines
2.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';
import selectTorrent, { UNION, SUBTRACT, EXCLUSIVE } from '../actions/selection';
2017-08-25 04:49:24 +02:00
import { formatBitrate } from '../bitrate';
2017-09-10 14:36:24 +02:00
import Ratio from './ratio';
import TorrentProgress from './torrent_progress';
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-26 01:59:53 +02:00
<th style={{width: "1px"}}>
<input
type="checkbox"
checked={selection.length === Object.values(torrents).length}
onChange={e => {
if (selection.length > 0) {
dispatch(selectTorrent([], EXCLUSIVE));
} else {
dispatch(selectTorrent(Object.keys(torrents), EXCLUSIVE));
}
}}
/>
</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>
<th>progress</th>
2017-08-22 21:49:48 +02:00
</tr>
</thead>
<tbody>
{Object.values(torrents).map(t =>
<tr
key={t.id}
className={`torrent ${
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
>
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 =>
2017-08-26 01:59:53 +02:00
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();
2017-08-26 01:59:53 +02:00
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-09-10 14:36:24 +02:00
<td><Ratio up={t.transferred_up} down={t.transferred_down} /></td>
<td><TorrentProgress torrent={t} /></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);