Remove the torrents store from the global scope
This commit is contained in:
parent
20c37e39ca
commit
e3849d5fd3
@ -45,7 +45,7 @@ function mapStateToProps(state) {
|
|||||||
movieStore: state.movieStore,
|
movieStore: state.movieStore,
|
||||||
showStore: state.showStore,
|
showStore: state.showStore,
|
||||||
userStore: state.userStore,
|
userStore: state.userStore,
|
||||||
torrentStore: state.torrentStore,
|
torrentCount: state.torrentStore.torrents.length,
|
||||||
alerts: state.alerts,
|
alerts: state.alerts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ function Main(props) {
|
|||||||
<NavBar
|
<NavBar
|
||||||
username={props.userStore.username}
|
username={props.userStore.username}
|
||||||
router={props.router}
|
router={props.router}
|
||||||
torrentCount={props.torrentStore.torrents.length}
|
torrentCount={props.torrentCount}
|
||||||
/>
|
/>
|
||||||
<Alert
|
<Alert
|
||||||
alerts={props.alerts}
|
alerts={props.alerts}
|
||||||
|
@ -1,15 +1,27 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import { connect } from 'react-redux'
|
||||||
|
import { bindActionCreators } from 'redux'
|
||||||
|
import { addTorrent } from '../../actions/actionCreators'
|
||||||
|
|
||||||
export default function TorrentList(props){
|
function mapStateToProps(state) {
|
||||||
return (
|
return { torrents: state.torrentStore.torrents };
|
||||||
<div>
|
|
||||||
<AddTorrent func={props.addTorrent} />
|
|
||||||
<List torrents={props.torrentStore.torrents} />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
const mapDispatchToProps = (dipatch) =>
|
||||||
|
bindActionCreators({ addTorrent }, dipatch)
|
||||||
|
|
||||||
class AddTorrent extends React.Component {
|
class TorrentList extends React.PureComponent {
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<AddTorrent func={this.props.addTorrent} />
|
||||||
|
<List torrents={this.props.torrents} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default connect(mapStateToProps, mapDispatchToProps)(TorrentList);
|
||||||
|
|
||||||
|
class AddTorrent extends React.PureComponent {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = { url: '' };
|
this.state = { url: '' };
|
||||||
@ -53,72 +65,75 @@ class AddTorrent extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function List(props){
|
class List extends React.PureComponent {
|
||||||
if (props.torrents.length === 0) {
|
render() {
|
||||||
|
if (this.props.torrents.length === 0) {
|
||||||
|
return (
|
||||||
|
<div className="row">
|
||||||
|
<div className="col-xs-12 col-md-12">
|
||||||
|
<h3>Torrents</h3>
|
||||||
|
<div className="panel panel-default">
|
||||||
|
<div className="panel-heading">No torrents</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<div className="col-xs-12 col-md-12">
|
<div className="col-xs-12 col-md-12">
|
||||||
<h3>Torrents</h3>
|
<h3>Torrents</h3>
|
||||||
<div className="panel panel-default">
|
{this.props.torrents.map(function(el, index) {
|
||||||
<div className="panel-heading">No torrents</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<div className="row">
|
|
||||||
<div className="col-xs-12 col-md-12">
|
|
||||||
<h3>Torrents</h3>
|
|
||||||
{props.torrents.map(function(el, index) {
|
|
||||||
return (
|
return (
|
||||||
<Torrent key={index} data={el} />
|
<Torrent key={index} data={el} />
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Torrent extends React.PureComponent {
|
||||||
|
render() {
|
||||||
|
const done = this.props.data.is_finished;
|
||||||
|
var progressStyle = 'progress-bar progress-bar-warning';
|
||||||
|
if (done) {
|
||||||
|
progressStyle = 'progress-bar progress-bar-success';
|
||||||
|
}
|
||||||
|
var percentDone = this.props.data.percent_done;
|
||||||
|
const started = (percentDone !== 0);
|
||||||
|
if (started) {
|
||||||
|
percentDone = Number(percentDone).toFixed(1) + '%';
|
||||||
|
}
|
||||||
|
|
||||||
function Torrent(props){
|
var downloadedSize = prettySize(this.props.data.downloaded_size);
|
||||||
const done = props.data.is_finished;
|
var totalSize = prettySize(this.props.data.total_size);
|
||||||
var progressStyle = 'progress-bar progress-bar-warning';
|
var downloadRate = prettySize(this.props.data.download_rate) + "/s";
|
||||||
if (done) {
|
return (
|
||||||
progressStyle = 'progress-bar progress-bar-success';
|
<div className="panel panel-default">
|
||||||
}
|
<div className="panel-heading">{this.props.data.name}</div>
|
||||||
var percentDone = props.data.percent_done;
|
<div className="panel-body">
|
||||||
const started = (percentDone !== 0);
|
{started &&
|
||||||
if (started) {
|
<div className="progress progress-striped">
|
||||||
percentDone = Number(percentDone).toFixed(1) + '%';
|
<div
|
||||||
}
|
className={progressStyle}
|
||||||
|
style={{width: percentDone}}>
|
||||||
var downloadedSize = prettySize(props.data.downloaded_size);
|
</div>
|
||||||
var totalSize = prettySize(props.data.total_size);
|
|
||||||
var downloadRate = prettySize(props.data.download_rate) + "/s";
|
|
||||||
return (
|
|
||||||
<div className="panel panel-default">
|
|
||||||
<div className="panel-heading">{props.data.name}</div>
|
|
||||||
<div className="panel-body">
|
|
||||||
{started &&
|
|
||||||
<div className="progress progress-striped">
|
|
||||||
<div
|
|
||||||
className={progressStyle}
|
|
||||||
style={{width: percentDone}}>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
}
|
||||||
}
|
{!started &&
|
||||||
{!started &&
|
<p>Download not yet started</p>
|
||||||
<p>Download not yet started</p>
|
}
|
||||||
}
|
{started &&
|
||||||
{started &&
|
<div>
|
||||||
<div>
|
<p>{downloadedSize} / {totalSize} - {percentDone} - {downloadRate}</p>
|
||||||
<p>{downloadedSize} / {totalSize} - {percentDone} - {downloadRate}</p>
|
</div>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
);
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function prettySize(fileSizeInBytes) {
|
function prettySize(fileSizeInBytes) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user