receptor/src/ui/ratio.js

31 lines
741 B
JavaScript
Raw Normal View History

2017-09-10 14:36:24 +02:00
import React, { Component } from 'react';
2017-11-05 22:58:40 +01:00
import FontAwesome from 'react-fontawesome';
2017-09-10 14:36:24 +02:00
import { formatAmount } from '../bitrate';
export default function Ratio({ up, down }) {
const ratio = up / down;
if (isNaN(ratio)) {
2017-12-29 08:07:40 +01:00
return <span class="ratio">
<span>0</span>
<span></span>
<span></span>
</span>;
2017-09-10 14:36:24 +02:00
}
2017-10-01 18:22:32 +02:00
if (!isFinite(ratio)) {
2017-12-29 08:07:40 +01:00
return <span class="ratio">
<strong></strong>
<span></span>
<span></span>
</span>;
2017-10-01 18:22:32 +02:00
}
2017-09-10 14:36:24 +02:00
return (
2017-12-29 08:07:40 +01:00
<span class="ratio">
2017-11-05 22:58:40 +01:00
<span>
2017-12-29 08:07:40 +01:00
{`${ratio.toFixed(2)}`}
2017-11-05 22:58:40 +01:00
</span>
2017-12-29 08:07:40 +01:00
<span>{formatAmount(up)} <FontAwesome name="arrow-up" /></span>
<span>{`${formatAmount(down)}`} <FontAwesome name="arrow-down" /></span>
2017-09-10 14:36:24 +02:00
</span>
);
}