Unsquash the UI when window is small

Fix #44
This commit is contained in:
Feross Aboukhadijeh
2016-03-06 01:03:20 -08:00
parent ad88d3bf67
commit 8b1b21c1ee
2 changed files with 63 additions and 54 deletions

View File

@@ -247,22 +247,28 @@ body.drag::before {
} }
.torrent:hover .metadata { .torrent:hover .metadata {
width: calc(100% - 170px); width: calc(100% - 90px);
} }
.torrent .btn, .torrent .delete { .torrent .buttons {
float: right; float: right;
margin-top: 20px; margin-top: 20px;
margin-left: 15px;
padding-top: 10px;
display: none; display: none;
} }
.torrent .buttons * {
padding-top: 10px;
}
.torrent .buttons :not(:first-child) {
margin-left: 10px;
}
.torrent .delete { .torrent .delete {
opacity: 0.5; opacity: 0.5;
} }
.torrent:hover .btn, .torrent:hover .delete { .torrent:hover .buttons {
display: block; display: block;
} }
@@ -284,11 +290,9 @@ body.drag::before {
line-height: 1.5em; line-height: 1.5em;
} }
.torrent .status { .torrent .status, .torrent .status2 {
font-size: 1em; font-size: 1em;
line-height: 1.5em; line-height: 1.5em;
position: absolute;
bottom: 20px;
} }
.torrent span:not(:last-child)::after { .torrent span:not(:last-child)::after {

View File

@@ -23,57 +23,62 @@ function renderTorrent (torrent, dispatch) {
// Foreground: name of the torrent, basic info like size, play button, // Foreground: name of the torrent, basic info like size, play button,
// cast buttons if available, and delete // cast buttons if available, and delete
var elements = [
renderTorrentMetadata(torrent),
hx`
<i
class='icon delete'
onclick=${() => dispatch('deleteTorrent', torrent)}>
close
</i>
`,
hx`
<i.btn.icon.play
class='${!torrent.ready ? 'disabled' : ''}'
onclick=${() => dispatch('openPlayer', torrent)}>
play_arrow
</i>
`
]
return hx`<div class='torrent' style=${style}>${elements}</div>`
}
// Renders the torrent name and download progress
function renderTorrentMetadata (torrent) {
var progress = Math.floor(100 * torrent.progress)
var downloaded = prettyBytes(torrent.downloaded)
var total = prettyBytes(torrent.length || 0)
if (downloaded !== total) downloaded += ` / ${total}`
return hx` return hx`
<div class='metadata'> <div class='torrent' style=${style}>
<div class='name ellipsis'>${torrent.name || 'Loading torrent...'}</div> ${renderTorrentMetadata(torrent)}
<div class='status'> ${renderTorrentButtons(torrent)}
<span class='progress'>${progress}%</span>
<span>${downloaded}</span>
</div>
${getFilesLength()}
<span>${getPeers()}</span>
<span>↓ ${prettyBytes(torrent.downloadSpeed || 0)}/s</span>
<span>↑ ${prettyBytes(torrent.uploadSpeed || 0)}/s</span>
</div> </div>
` `
function getPeers () { function renderTorrentMetadata () {
var count = torrent.numPeers === 1 ? 'peer' : 'peers' var progress = Math.floor(100 * torrent.progress)
return `${torrent.numPeers} ${count}` var downloaded = prettyBytes(torrent.downloaded)
} var total = prettyBytes(torrent.length || 0)
function getFilesLength () { if (downloaded !== total) downloaded += ` / ${total}`
if (torrent.ready && torrent.files.length > 1) {
return hx`<span class='files'>${torrent.files.length} files</span>` return hx`
<div class='metadata'>
<div class='name ellipsis'>${torrent.name || 'Loading torrent...'}</div>
<div class='status ellipsis'>
${getFilesLength()}
<span>${getPeers()}</span>
<span>↓ ${prettyBytes(torrent.downloadSpeed || 0)}/s</span>
<span>↑ ${prettyBytes(torrent.uploadSpeed || 0)}/s</span>
</div>
<div class='status2 ellipsis'>
<span class='progress'>${progress}%</span>
<span>${downloaded}</span>
</div>
</div>
`
function getPeers () {
var count = torrent.numPeers === 1 ? 'peer' : 'peers'
return `${torrent.numPeers} ${count}`
}
function getFilesLength () {
if (torrent.ready && torrent.files.length > 1) {
return hx`<span class='files'>${torrent.files.length} files</span>`
}
} }
} }
function renderTorrentButtons () {
return hx`
<div class="buttons">
<i.btn.icon.play
class='${!torrent.ready ? 'disabled' : ''}'
onclick=${() => dispatch('openPlayer', torrent)}>
play_arrow
</i>
<i
class='icon delete'
onclick=${() => dispatch('deleteTorrent', torrent)}>
close
</i>
</div>
`
}
} }