исправление роутинга, отображение общей статистики

This commit is contained in:
Alexey Kasyanchuk 2017-01-02 15:15:47 +03:00
parent e988f11891
commit 0549f099f0
2 changed files with 30 additions and 1 deletions

View File

@ -69,6 +69,11 @@ app.get('/', function(req, res)
app.use(express.static('build')); app.use(express.static('build'));
app.get('*', function(req, res)
{
res.sendfile(__dirname + '/build/index.html');
});
io.on('connection', function(socket) io.on('connection', function(socket)
{ {
function baseRowData(row) function baseRowData(row)
@ -96,6 +101,18 @@ io.on('connection', function(socket)
}); });
}); });
socket.on('statistic', function(callback)
{
let stats = {};
socketMysql.query('SELECT COUNT(*) as tornum FROM `torrents`', function (error, rows, fields) {
stats.torrents = rows[0].tornum;
socketMysql.query('SELECT COUNT(*) as filesnum FROM `files`', function (error, rows, fields) {
stats.files = rows[0].filesnum;
callback(stats)
});
});
});
socket.on('torrent', function(hash, options, callback) socket.on('torrent', function(hash, options, callback)
{ {
if(hash.length != 40) if(hash.length != 40)

View File

@ -6,12 +6,17 @@ import RaisedButton from 'material-ui/RaisedButton';
export default class Search extends Component { export default class Search extends Component {
search() { search() {
console.log(this.searchValue);
window.torrentSocket.emit('search', this.searchValue, (torrents) => { window.torrentSocket.emit('search', this.searchValue, (torrents) => {
this.searchData = torrents; this.searchData = torrents;
this.forceUpdate(); this.forceUpdate();
}); });
} }
componentDidMount() {
window.torrentSocket.emit('statistic', (statistic) => {
this.stats = statistic;
this.forceUpdate();
});
}
render() { render() {
return ( return (
<div className="column w100p center"> <div className="column w100p center">
@ -32,6 +37,13 @@ export default class Search extends Component {
this.search() this.search()
}} /> }} />
</div> </div>
{
this.stats
?
<div className='fs0-75' style={{color: 'rgba(0, 0, 0, 0.541176)'}}>we have {this.stats.torrents} torrents and around {this.stats.files} files here</div>
:
null
}
<SearchResults results={this.searchData} /> <SearchResults results={this.searchData} />
</div> </div>
); );