diff --git a/src/app/top-page.js b/src/app/top-page.js index f0ed1ef..b34ecd9 100644 --- a/src/app/top-page.js +++ b/src/app/top-page.js @@ -2,11 +2,14 @@ import React from 'react'; import Page from './page'; import TorrentLine from './torrent' -import {List} from 'material-ui/List'; +import {List, ListItem} from 'material-ui/List'; +import Divider from 'material-ui/Divider'; import Subheader from 'material-ui/Subheader'; import RaisedButton from 'material-ui/RaisedButton'; import LinearProgress from 'material-ui/LinearProgress'; +import {Tabs, Tab} from 'material-ui/Tabs'; + export default class TopPage extends Page { constructor(props) { super(props) @@ -25,16 +28,31 @@ export default class TopPage extends Page { hours: 'Last 24 hours', month: 'Last month' } + this.state = {value: 'All'} + } + loadMoreTorrents(type) + { + window.torrentSocket.emit('topTorrents', + type == 'main' ? null : type, + {index: (this.topTorrents[type] && this.topTorrents[type].length) || 0}, + window.customLoader((data) => { + if(!this.topTorrents[type]) + this.topTorrents[type] = [] + if(data && data.length > 0) + { + this.topTorrents[type] = this.topTorrents[type].concat(data); + this.forceUpdate() + } + console.log(type, this.topTorrents[type]) + }) + ) } componentDidMount() { super.componentDidMount(); for(const type of this.types) { - window.torrentSocket.emit('topTorrents', type == 'main' ? null : type, window.customLoader((data) => { - this.topTorrents[type] = data; - this.forceUpdate() - })) + this.loadMoreTorrents(type) } this.remoteTopTorrents = ({torrents, type}) => { if(!torrents) @@ -49,13 +67,16 @@ export default class TopPage extends Page { if(this.remoteTopTorrents) window.torrentSocket.off('remoteTopTorrents', this.remoteTopTorrents); } + handleChange = (value) => + { + this.setState({ + value, + }); + } render() { return (
-
- { - window.router('/') - }} /> +
{ Object.keys(this.topTorrents).length == 0 && @@ -63,6 +84,11 @@ export default class TopPage extends Page {
} + { this.types.map((type, index) => { const torrents = this.topTorrents[type]; @@ -71,22 +97,27 @@ export default class TopPage extends Page { return null; return ( - - - { - this.descriptions[type] - } - - { - torrents.map((torrent, index) => { - return - }) - } - + + + + { + torrents.map((torrent, index) => { + return + }) + } +
+ More Torrents} onClick={() => { + this.loadMoreTorrents(type) + }} /> + +
+
+
) }) } +
); diff --git a/src/background/api.js b/src/background/api.js index 888019b..510baec 100644 --- a/src/background/api.js +++ b/src/background/api.js @@ -389,29 +389,34 @@ module.exports = ({ updateTorrentTrackers(hash); }); - const topTorrentsCall = (type, callback) => { + const topTorrentsCall = (type, navigation = {}, callback) => { let where = ''; - let max = 20; + + const index = parseInt(navigation.index) || 0; + const limit = parseInt(navigation.limit) || 20; + if(type && type.length > 0) { - where += ' and contentType = ' + sphinx.escape(type) + ' '; - max = 15; - if(type == 'hours') { - where = ' and `added` > ' + Math.floor(Date.now() / 1000) - (60 * 60 * 24) + where = ' and `added` > ' + (Math.floor(Date.now() / 1000) - (60 * 60 * 24)) } - if(type == 'week') + else if(type == 'week') { - where = ' and `added` > ' + Math.floor(Date.now() / 1000) - (60 * 60 * 24 * 7) + where = ' and `added` > ' + (Math.floor(Date.now() / 1000) - (60 * 60 * 24 * 7)) } - if(type == 'month') + else if(type == 'month') { - where = ' and `added` > ' + Math.floor(Date.now() / 1000) - (60 * 60 * 24 * 30) + where = ' and `added` > ' + (Math.floor(Date.now() / 1000) - (60 * 60 * 24 * 30)) + } + else + { + where += ' and contentType = ' + sphinx.escape(type) + ' '; } } - const query = `SELECT * FROM torrents WHERE seeders > 0 and contentCategory != 'xxx' ${where} ORDER BY seeders DESC LIMIT ${max}`; + const query = `SELECT * FROM torrents WHERE seeders > 0 and contentCategory != 'xxx' ${where} ORDER BY seeders DESC LIMIT ${index},${limit}`; + console.log(query) if(topCache[query]) { callback(topCache[query]); @@ -423,18 +428,16 @@ module.exports = ({ return; } - rows = rows.map((row) => { - return baseRowData(row); - }); + rows = rows.map((row) => baseRowData(row)); topCache[query] = rows; callback(rows); }); } - recive('topTorrents', (type, callback) => + recive('topTorrents', (type, navigation, callback) => { - topTorrentsCall(type, callback) - p2p.emit('topTorrents', {type}, (remote, socketObject) => { + topTorrentsCall(type, navigation, callback) + p2p.emit('topTorrents', {type, navigation}, (remote, socketObject) => { console.log('remote top results', remote && remote.length) if(remote && remote.length > 0) { @@ -446,8 +449,8 @@ module.exports = ({ }) }); - p2p.on('topTorrents', ({type} = {}, callback) => { - topTorrentsCall(type, (data) => callback(data)) + p2p.on('topTorrents', ({type, navigation} = {}, callback) => { + topTorrentsCall(type, navigation, (data) => callback(data)) }) recive('peers', (callback) =>