кнопка остановки обновления списка

This commit is contained in:
Alexey Kasyanchuk 2017-01-05 07:20:04 +03:00
parent 916c421a19
commit 64f1e107a4
3 changed files with 40 additions and 5 deletions

View File

@ -339,4 +339,4 @@ client.on('complete', function (metadata, infohash, rinfo) {
// spider.on('nodes', (nodes)=>console.log('foundNodes')) // spider.on('nodes', (nodes)=>console.log('foundNodes'))
spider.listen(4445) //spider.listen(4445)

View File

@ -13,3 +13,10 @@
width: 100%; width: 100%;
} }
} }
@media only screen and (max-width: 445px)
{
.recent-title {
padding-left: 10px !important;
}
}

View File

@ -5,6 +5,7 @@ import {List, ListItem} from 'material-ui/List';
import Subheader from 'material-ui/Subheader'; import Subheader from 'material-ui/Subheader';
import Paper from 'material-ui/Paper'; import Paper from 'material-ui/Paper';
import Divider from 'material-ui/Divider'; import Divider from 'material-ui/Divider';
import FlatButton from 'material-ui/FlatButton';
const TorrentLine = (props) => { const TorrentLine = (props) => {
const torrent = props.torrent; const torrent = props.torrent;
@ -146,6 +147,8 @@ export default class RecentTorrents extends Component {
constructor() { constructor() {
super() super()
this.torrents = []; this.torrents = [];
this.displayQueue = [];
this.state = { pause: false }
} }
componentDidMount() { componentDidMount() {
window.torrentSocket.emit('recentTorrents', (data) => { window.torrentSocket.emit('recentTorrents', (data) => {
@ -153,18 +156,38 @@ export default class RecentTorrents extends Component {
this.torrents = data; this.torrents = data;
this.forceUpdate(); this.forceUpdate();
} }
});
this.newTorrentFunc = (torrent) => { this.displayNewTorrent = setInterval(() => {
if(this.displayQueue.length == 0)
return;
if(this.state.pause)
return;
let torrent = this.displayQueue.shift();
this.torrents.unshift(torrent); this.torrents.unshift(torrent);
if(this.torrents.length > 10) if(this.torrents.length > 10)
this.torrents.pop() this.torrents.pop()
this.forceUpdate();
}, 850);
});
this.newTorrentFunc = (torrent) => {
this.displayQueue.push(torrent);
this.forceUpdate(); this.forceUpdate();
}; };
window.torrentSocket.on('newTorrent', this.newTorrentFunc); window.torrentSocket.on('newTorrent', this.newTorrentFunc);
} }
pauseAndContinue() {
this.setState({
pause: !this.state.pause
});
}
componentWillUnmount() { componentWillUnmount() {
if(this.newTorrentFunc) if(this.newTorrentFunc)
window.torrentSocket.off('newTorrent', this.newTorrentFunc); window.torrentSocket.off('newTorrent', this.newTorrentFunc);
if(this.displayNewTorrent)
clearInterval(this.displayNewTorrent);
} }
render() { render() {
if(!this.torrents || this.torrents.length == 0) if(!this.torrents || this.torrents.length == 0)
@ -172,7 +195,12 @@ export default class RecentTorrents extends Component {
return ( return (
<List className='animated'> <List className='animated'>
<Subheader inset={true}>Most recent torrents</Subheader> <Subheader className='recent-title' inset={true}>
<FlatButton style={{marginRight: '8px'}} label={!this.state.pause ? 'running' : 'stoped'} secondary={this.state.pause} primary={!this.state.pause} onClick={() =>{
this.pauseAndContinue()
}} />
Most recent torrents{this.displayQueue.length > 0 ? ` (and ${this.displayQueue.length} more)` : null}
</Subheader>
<Divider /> <Divider />
{ {
this.torrents.map((torrent, index) =>{ this.torrents.map((torrent, index) =>{