Merge pull request #20 from feross/metadata

improve torrent metadata display
This commit is contained in:
Feross Aboukhadijeh
2016-03-05 13:26:43 -08:00
3 changed files with 19 additions and 7 deletions

View File

@@ -266,7 +266,7 @@ body.drag::before {
bottom: 20px; bottom: 20px;
} }
.torrent .status :not(:last-child)::after { .torrent span:not(:last-child)::after {
content: ' — '; content: ' — ';
} }

View File

@@ -72,7 +72,7 @@ function init () {
dragDrop('body', onFiles) dragDrop('body', onFiles)
chromecasts.on('update', function (player) { chromecasts.on('update', function (player) {
state.view.chromecast = player state.view.devices.chromecast = player
update() update()
}) })
@@ -285,8 +285,8 @@ function deleteTorrent (torrent) {
function openChromecast (torrent) { function openChromecast (torrent) {
startServer(torrent, function () { startServer(torrent, function () {
state.view.chromecast.play(state.server.networkURL, { title: 'WebTorrent — ' + torrent.name }) state.view.devices.chromecast.play(state.server.networkURL, { title: 'WebTorrent — ' + torrent.name })
state.view.chromecast.on('error', function (err) { state.view.devices.chromecast.on('error', function (err) {
err.message = 'Chromecast: ' + err.message err.message = 'Chromecast: ' + err.message
onError(err) onError(err)
}) })

View File

@@ -49,16 +49,28 @@ function renderTorrent (state, dispatch, torrent) {
// Renders the torrent name and download progress // Renders the torrent name and download progress
function renderTorrentMetadata (torrent) { function renderTorrentMetadata (torrent) {
var progressPercent = 0
var progressBytes = 0
if (torrent.progress) {
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">${Math.floor(100 * torrent.progress)}%</span> <span class="progress">${progressPercent}%</span>
<span>${prettyBytes(progressBytes)} / ${prettyBytes(torrent.length || 0)}</span>
</div> </div>
${getFilesLength()} ${getFilesLength()}
<span>${getPeers()}</span> <span>${getPeers()}</span>
<span>${prettyBytes(torrent.downloadSpeed)}/s</span> <span>${prettyBytes(torrent.downloadSpeed || 0)}/s</span>
<span>${prettyBytes(torrent.uploadSpeed)}/s</span> <span>${prettyBytes(torrent.uploadSpeed || 0)}/s</span>
</div> </div>
` `