feat(gui): display rating in torrent line (gui part)
This commit is contained in:
parent
9502e53fc1
commit
a9c27083da
@ -8,6 +8,7 @@ import TorrentPage from './torrent-page'
|
|||||||
|
|
||||||
import Spinner24 from './images/spinner_24.gif'
|
import Spinner24 from './images/spinner_24.gif'
|
||||||
import LinearProgress from 'material-ui/LinearProgress';
|
import LinearProgress from 'material-ui/LinearProgress';
|
||||||
|
let rating = require('./rating');
|
||||||
|
|
||||||
const contentIcon = (type, category, fill = 'grey') => {
|
const contentIcon = (type, category, fill = 'grey') => {
|
||||||
if(category == 'xxx')
|
if(category == 'xxx')
|
||||||
@ -218,6 +219,10 @@ export default class Torrent extends Component {
|
|||||||
render()
|
render()
|
||||||
{
|
{
|
||||||
const torrent = this.props.torrent;
|
const torrent = this.props.torrent;
|
||||||
|
let torrentRating = -1
|
||||||
|
if(torrent.good > 0 || torrent.bad > 0)
|
||||||
|
torrentRating = Math.round(rating(torrent.good, torrent.bad) * 100);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<ListItem
|
<ListItem
|
||||||
@ -290,6 +295,21 @@ export default class Torrent extends Component {
|
|||||||
:
|
:
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
(torrent.good > 0 || torrent.bad > 0)
|
||||||
|
&&
|
||||||
|
<div className='row w100p inline' style={{maxWidth: 600}}>
|
||||||
|
<LinearProgress
|
||||||
|
mode="determinate"
|
||||||
|
value={torrentRating}
|
||||||
|
color={torrentRating >= 50 ? '#00E676' : '#FF3D00'}
|
||||||
|
style={{
|
||||||
|
height: '5px',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div className='row center pad0-5 fs0-85 text-nowrap' style={{color: torrentRating >= 50 ? '#00E676' : '#FF3D00', width: '190px'}}>{__('Torrent rating')}: {torrentRating}%</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
|
@ -757,6 +757,10 @@ module.exports = async ({
|
|||||||
if(torrent.hash !== record.torrentHash)
|
if(torrent.hash !== record.torrentHash)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
let {good, bad} = await getVotes(torrent.hash)
|
||||||
|
torrent.good = good
|
||||||
|
torrent.bad = bad
|
||||||
|
|
||||||
feed.add(torrent)
|
feed.add(torrent)
|
||||||
|
|
||||||
send('feedUpdate', {
|
send('feedUpdate', {
|
||||||
|
@ -4,6 +4,12 @@ module.exports = class Feed {
|
|||||||
this.feed = []
|
this.feed = []
|
||||||
this.sphinx = sphinx
|
this.sphinx = sphinx
|
||||||
this.loaded = false
|
this.loaded = false
|
||||||
|
this.max = 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
size()
|
||||||
|
{
|
||||||
|
return this.feed.length
|
||||||
}
|
}
|
||||||
|
|
||||||
async save() {
|
async save() {
|
||||||
@ -39,12 +45,35 @@ module.exports = class Feed {
|
|||||||
}
|
}
|
||||||
|
|
||||||
add(data) {
|
add(data) {
|
||||||
if(typeof data == 'object')
|
let index = -1
|
||||||
|
if(data.hash)
|
||||||
|
index = this.feed.findIndex(element => element.hash === data.hash)
|
||||||
|
|
||||||
|
if(index >= 0)
|
||||||
|
this.feed[index] = Object.assign(this.feed[index], data) // just push up element
|
||||||
|
else
|
||||||
{
|
{
|
||||||
data.feedDate = Math.floor(Date.now() / 1000)
|
if(this.feed.length >= this.max)
|
||||||
|
{
|
||||||
|
//cleanup
|
||||||
|
for(let i = this.feed.length - 1; i <= 0; i--)
|
||||||
|
if(this._compare(this.feed[i]) <= 0)
|
||||||
|
this.feed.pop()
|
||||||
|
else
|
||||||
|
break
|
||||||
|
|
||||||
|
if(this.feed.length >= this.max)
|
||||||
|
return // two much for feed
|
||||||
|
}
|
||||||
|
|
||||||
|
if(typeof data == 'object')
|
||||||
|
{
|
||||||
|
data.feedDate = Math.floor(Date.now() / 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.feed.push(data) // insert
|
||||||
}
|
}
|
||||||
|
|
||||||
this.feed.push(data)
|
|
||||||
this._order()
|
this._order()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +83,7 @@ module.exports = class Feed {
|
|||||||
|
|
||||||
_compare(x)
|
_compare(x)
|
||||||
{
|
{
|
||||||
const rating = 0
|
const rating = (x && x.good) || 0
|
||||||
const comments = 0
|
const comments = 0
|
||||||
const time = Math.floor(Date.now() / 1000) - x.feedDate
|
const time = Math.floor(Date.now() / 1000) - x.feedDate
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user