diff options
author | Florrie <towerofnix@gmail.com> | 2019-06-07 16:22:18 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2019-06-07 16:22:18 -0300 |
commit | fb8f3703b183037140c57b7e1d1f6f265778c5d4 (patch) | |
tree | 5e334dc1a381d64ec9961aa66f4c48b90eaae477 | |
parent | 86af38d56742269ae2d0fbffcab636ee1ce9c1dd (diff) |
"Play sooner" context menu option in queue
-rw-r--r-- | ui.js | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/ui.js b/ui.js index 1bb74fc..e837256 100644 --- a/ui.js +++ b/ui.js @@ -390,13 +390,40 @@ class AppElement extends FocusElement { } } + playSooner(item) { + this.distributeQueueGrouplikeItem(item, { + how: 'randomly', + rangeEnd: this.queueGrouplike.items.indexOf(item) + }) + + // It may not have queued as soon as the user wants; in that acse, they'll + // want to queue it sooner again. Automatically reselect the track so that + // this they don't have to navigate back to it by hand. + this.queueListingElement.selectAndShow(item) + } + playLater(item) { this.handleQueueOptions(item, { where: 'distribute-randomly', skip: true }) + + // Just for consistency with playSooner (you can press ^-L to quickly get + // back to the current track). + this.queueListingElement.selectAndShow(item) } + playLater(item) { + this.handleQueueOptions(item, { + where: 'distribute-randomly', + skip: true + }) + + // Just for consistency. + this.queueListingElement.selectAndShow(item) + } + + showMenuForItemElement(el, listing) { const emitControls = play => () => { this.handleQueueOptions(item, { @@ -416,6 +443,7 @@ class AppElement extends FocusElement { {label: 'Reveal', action: () => this.reveal(item)}, {divider: true}, {label: 'Play later', action: () => this.playLater(item)}, + {label: 'Play sooner', action: () => this.playSooner(item)}, {label: 'Remove from queue', action: () => this.unqueueGrouplikeItem(item)} ] } else { @@ -766,7 +794,9 @@ class AppElement extends FocusElement { movePlayingTrack: order === 'normal' }) } else if (where.startsWith('distribute-')) { - this.distributeQueueGrouplikeItem(item, where.slice('distribute-'.length)) + this.distributeQueueGrouplikeItem(item, { + how: where.slice('distribute-'.length) + }) } if (play) { @@ -834,7 +864,11 @@ class AppElement extends FocusElement { return newTrack } - distributeQueueGrouplikeItem(grouplike, how = 'evenly') { + distributeQueueGrouplikeItem(grouplike, {how = 'evenly', rangeEnd = 'end-of-queue'}) { + if (isTrack(grouplike)) { + grouplike = {items: [grouplike]} + } + const queue = this.queueGrouplike const newItems = flattenGrouplike(grouplike).items @@ -854,7 +888,16 @@ class AppElement extends FocusElement { } const distributeStart = queue.items.indexOf(this.playingTrack) + 1 - const distributeEnd = queue.items.length + + let distributeEnd + if (rangeEnd === 'end-of-queue') { + distributeEnd = queue.items.length + } else if (typeof rangeEnd === 'number') { + distributeEnd = Math.min(queue.items.length, rangeEnd) + } else { + throw new Error('Invalid rangeEnd: ' + rangeEnd) + } + const distributeSize = distributeEnd - distributeStart const queueItem = (item, insertIndex) => { |