Implement tracker list

This commit is contained in:
Drew DeVault 2017-09-10 20:50:37 +09:00
parent f44e7a3001
commit 1504288692

View File

@ -73,7 +73,7 @@ class Torrent extends Component {
} }
render() { render() {
const { dispatch, torrent, files } = this.props; const { dispatch, torrent, files, trackers } = this.props;
const status = s => s[0].toUpperCase() + s.slice(1); const status = s => s[0].toUpperCase() + s.slice(1);
if (!torrent || !files) { if (!torrent || !files) {
@ -175,6 +175,35 @@ class Torrent extends Component {
</CardBlock> </CardBlock>
</Card> </Card>
</Collapse> </Collapse>
<Collapse isOpen={this.state.trackersShown}>
<Card style={{marginBottom: "1rem"}}>
<CardBlock>
{trackers.map(tracker =>
<div>
<h5>{(() => {
const a = document.createElement("a");
a.href = tracker.url;
return a.hostname;
})()}
{/* TODO: wire up this button: */}
<button
className="btn btn-sm btn-outline-primary pull-right"
>Report</button>
</h5>
<dl>
<dt>URL</dt>
<dd>{tracker.url}</dd>
<dt>Last report</dt>
<dd>{date(moment(tracker.last_report))}</dd>
{tracker.error && <dt>Error</dt>}
{tracker.error &&
<dd className="text-danger">{tracker.error}</dd>}
</dl>
</div>
)}
</CardBlock>
</Card>
</Collapse>
</div> </div>
); );
} }
@ -247,10 +276,23 @@ class TorrentDetails extends Component {
} }
render() { render() {
const { torrents, files, selection, dispatch } = this.props; const {
torrents,
files,
trackers,
peers,
selection,
dispatch
} = this.props;
const _files = Object.values(files).reduce((s, f) => ({ const _files = Object.values(files).reduce((s, f) => ({
...s, [f.torrent_id]: [...(s[f.torrent_id] || []), f] ...s, [f.torrent_id]: [...(s[f.torrent_id] || []), f]
}), {}); }), {});
const _trackers = Object.values(trackers).reduce((s, t) => ({
...s, [t.torrent_id]: [...(s[t.torrent_id] || []), t]
}), {});
const _peers = Object.values(peers).reduce((s, p) => ({
...s, [p.torrent_id]: [...(s[p.torrent_id] || []), p]
}), {});
return ( return (
<div> <div>
{selection.length > 1 ? this.renderHeader.bind(this)() : null} {selection.length > 1 ? this.renderHeader.bind(this)() : null}
@ -258,6 +300,8 @@ class TorrentDetails extends Component {
dispatch={dispatch} dispatch={dispatch}
torrent={torrents[id]} torrent={torrents[id]}
files={_files[id] || []} files={_files[id] || []}
trackers={_trackers[id] || []}
peers={_peers[id] || []}
/>)} />)}
{selection.length > 3 ? {selection.length > 3 ?
<p class="text-center text-muted"> <p class="text-center text-muted">
@ -275,6 +319,8 @@ export default connect(state => ({
router: state.router, router: state.router,
torrents: state.torrents, torrents: state.torrents,
files: state.files, files: state.files,
trackers: state.trackers,
peers: state.peers,
selection: state.selection, selection: state.selection,
server: state.server server: state.server
}))(TorrentDetails); }))(TorrentDetails);