базовый клиент на сайте
This commit is contained in:
35
src/recent-torrents.js
Normal file
35
src/recent-torrents.js
Normal file
@ -0,0 +1,35 @@
|
||||
import React, { Component } from 'react';
|
||||
|
||||
export default class RecentTorrents extends Component {
|
||||
constructor() {
|
||||
super()
|
||||
this.torrents = [];
|
||||
}
|
||||
componentDidMount() {
|
||||
window.torrentSocket.emit('recentTorrents', (data) => {
|
||||
this.torrents = data;
|
||||
this.forceUpdate();
|
||||
});
|
||||
window.torrentSocket.on('newTorrent', (torrent) => {
|
||||
this.torrents.unshift(torrent);
|
||||
if(this.torrents.length > 10)
|
||||
this.torrents.pop()
|
||||
this.forceUpdate();
|
||||
});
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
<div className="list column">
|
||||
{
|
||||
this.torrents.map((torrent, index) =>{
|
||||
return(
|
||||
<div key={index}>
|
||||
{torrent.name}
|
||||
</div>
|
||||
);
|
||||
})
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user