import React from "react"
import { connect } from "react-redux"
import { bindActionCreators } from "redux"
import { addTorrent } from "../../actions/torrents"
function mapStateToProps(state) {
return { torrents: state.torrentStore.get("torrents") };
}
const mapDispatchToProps = (dispatch) =>
bindActionCreators({ addTorrent }, dispatch)
class TorrentList extends React.PureComponent {
render() {
return (
);
}
}
export default connect(mapStateToProps, mapDispatchToProps)(TorrentList);
class AddTorrent extends React.PureComponent {
constructor(props) {
super(props);
this.state = { url: "" };
this.handleSubmit = this.handleSubmit.bind(this);
this.handleChange = this.handleChange.bind(this);
}
handleChange(event) {
this.setState({ url: event.target.value });
}
handleSubmit() {
if (this.state.url === "") {
return;
}
this.setState({ url: "" });
this.props.func(this.state.url);
}
render() {
return (
);
}
}
class List extends React.PureComponent {
render() {
if (this.props.torrents.size === 0) {
return (
);
}
return (
Torrents
{this.props.torrents.map(function(el, index) {
return (
);
})}
);
}
}
class Torrent extends React.PureComponent {
render() {
const done = this.props.data.get("is_finished");
var progressStyle = "progress-bar progress-bar-warning";
if (done) {
progressStyle = "progress-bar progress-bar-success";
}
var percentDone = this.props.data.get("percent_done");
const started = (percentDone !== 0);
if (started) {
percentDone = Number(percentDone).toFixed(1) + "%";
}
var downloadedSize = prettySize(this.props.data.get("downloaded_size"));
var totalSize = prettySize(this.props.data.get("total_size"));
var downloadRate = prettySize(this.props.data.get("download_rate")) + "/s";
return (
{this.props.data.get("name")}
{started &&
}
{!started &&
Download not yet started
}
{started &&
{downloadedSize} / {totalSize} - {percentDone} - {downloadRate}
}
);
}
}
function prettySize(fileSizeInBytes) {
var i = -1;
var byteUnits = [" kB", " MB", " GB", " TB", "PB", "EB", "ZB", "YB"];
do {
fileSizeInBytes = fileSizeInBytes / 1024;
i++;
} while (fileSizeInBytes > 1024);
return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i];
};