improve progress percent & bytes display

This commit is contained in:
Nate Goldman
2016-03-05 18:41:20 -08:00
parent 4f1dfc8c1e
commit 2a52dbb600

View File

@@ -45,23 +45,18 @@ function renderTorrent (torrent, dispatch) {
// Renders the torrent name and download progress // Renders the torrent name and download progress
function renderTorrentMetadata (torrent) { function renderTorrentMetadata (torrent) {
var progressPercent = 0 var progress = Math.floor(100 * (torrent.progress || 0))
var progressBytes = 0 var downloaded = prettyBytes(torrent.downloaded || 0)
var total = prettyBytes(torrent.length || 0)
if (torrent.progress) { if (downloaded !== total) downloaded += ` / ${total}`
progressPercent = Math.floor(100 * torrent.progress)
}
if (torrent.length && torrent.progress) {
progressBytes = torrent.length * torrent.progress
}
return hx` return hx`
<div class="metadata"> <div class="metadata">
<div class="name ellipsis">${torrent.name || 'Loading torrent...'}</div> <div class="name ellipsis">${torrent.name || 'Loading torrent...'}</div>
<div class="status"> <div class="status">
<span class="progress">${progressPercent}%</span> <span class="progress">${progress}%</span>
<span>${prettyBytes(progressBytes)} / ${prettyBytes(torrent.length || 0)}</span> <span>${downloaded}</span>
</div> </div>
${getFilesLength()} ${getFilesLength()}
<span>${getPeers()}</span> <span>${getPeers()}</span>