2017-08-25 03:46:55 +02:00
|
|
|
import React, { Component } from 'react';
|
2017-08-25 02:01:15 +02:00
|
|
|
import { connect } from 'react-redux';
|
2017-08-25 03:46:55 +02:00
|
|
|
import { activeTorrents } from '../torrent_state';
|
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
ButtonGroup,
|
|
|
|
ButtonDropdown,
|
|
|
|
DropdownToggle,
|
|
|
|
DropdownMenu,
|
|
|
|
DropdownItem
|
|
|
|
} from 'reactstrap';
|
2017-08-24 14:30:22 +02:00
|
|
|
|
2017-08-25 03:13:01 +02:00
|
|
|
// TODO: use component lifecycle functions here to invoke
|
|
|
|
// torrent_state.updateSubscriptions
|
|
|
|
|
2017-08-25 03:46:55 +02:00
|
|
|
function Torrent(props) {
|
2017-08-24 14:30:22 +02:00
|
|
|
return (
|
|
|
|
<div>
|
2017-08-25 03:46:55 +02:00
|
|
|
<h3>{props.torrent.name}</h3>
|
2017-08-24 14:30:22 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-08-25 03:46:55 +02:00
|
|
|
class TorrentDetails extends Component {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.state = {
|
|
|
|
removeDropdown: false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
renderHeader(active) {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<h3>{active.length} torrents</h3>
|
|
|
|
<ButtonGroup>
|
|
|
|
<Button color="info">Pause all</Button>{' '}
|
|
|
|
<Button color="success">Resume all</Button>{' '}
|
|
|
|
<ButtonDropdown
|
|
|
|
isOpen={this.state.removeDropdown}
|
|
|
|
toggle={() => this.setState({ removeDropdown: !this.state.removeDropdown })}
|
|
|
|
>
|
|
|
|
<DropdownToggle color="danger" caret>
|
|
|
|
Remove
|
|
|
|
</DropdownToggle>
|
|
|
|
<DropdownMenu>
|
|
|
|
<DropdownItem>Remove torrent</DropdownItem>
|
|
|
|
<DropdownItem>Delete files</DropdownItem>
|
|
|
|
</DropdownMenu>
|
|
|
|
</ButtonDropdown>
|
|
|
|
</ButtonGroup>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const active = activeTorrents();
|
|
|
|
const { torrents } = this.props;
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{active.length > 1 ? this.renderHeader(active) : null}
|
|
|
|
{active.map(id => <Torrent torrent={torrents[id]} />)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(state => ({
|
|
|
|
router: state.router,
|
|
|
|
torrents: state.torrents
|
|
|
|
}))(TorrentDetails);
|