2018-11-23 08:04:42 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
|
|
|
import Label from 'Components/Label';
|
2020-07-28 20:47:25 +02:00
|
|
|
import { kinds } from 'Helpers/Props';
|
2018-11-23 08:04:42 +01:00
|
|
|
|
|
|
|
function getKind(seeders) {
|
|
|
|
if (seeders > 50) {
|
|
|
|
return kinds.PRIMARY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (seeders > 10) {
|
|
|
|
return kinds.INFO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (seeders > 0) {
|
|
|
|
return kinds.WARNING;
|
|
|
|
}
|
|
|
|
|
|
|
|
return kinds.DANGER;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPeersTooltipPart(peers, peersUnit) {
|
|
|
|
if (peers == null) {
|
2019-04-13 05:25:58 +02:00
|
|
|
return `Unknown ${peersUnit}s`;
|
2018-11-23 08:04:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (peers === 1) {
|
|
|
|
return `1 ${peersUnit}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return `${peers} ${peersUnit}s`;
|
|
|
|
}
|
|
|
|
|
|
|
|
function Peers(props) {
|
|
|
|
const {
|
|
|
|
seeders,
|
|
|
|
leechers
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
const kind = getKind(seeders);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Label
|
|
|
|
kind={kind}
|
|
|
|
title={`${getPeersTooltipPart(seeders, 'seeder')}, ${getPeersTooltipPart(leechers, 'leecher')}`}
|
|
|
|
>
|
|
|
|
{seeders == null ? '-' : seeders} / {leechers == null ? '-' : leechers}
|
|
|
|
</Label>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Peers.propTypes = {
|
|
|
|
seeders: PropTypes.number,
|
|
|
|
leechers: PropTypes.number
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Peers;
|