diff options
author | Florrie <towerofnix@gmail.com> | 2018-07-30 19:12:25 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-07-30 19:12:25 -0300 |
commit | b18eebf056b69fe46d7c980454b8ea95132b2e7e (patch) | |
tree | 891721849bdc2585255a267a258d1f1faa94fab4 | |
parent | 3c27a1bbd3fc0d496ee022c9ddcd1a59ee224903 (diff) |
Clean up select code
-rw-r--r-- | ui.js | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/ui.js b/ui.js index 0a722ea..c7ddfac 100644 --- a/ui.js +++ b/ui.js @@ -61,9 +61,8 @@ class AppElement extends FocusElement { this.paneRight.addChild(this.queueListingElement) this.form.addInput(this.queueListingElement, false) - this.queueListingElement.on('select (enter)', item => this.playGrouplikeItem(item, false)) - this.queueListingElement.on('select (space)', item => this.handleSpacePressed( - () => this.playGrouplikeItem(item, false))) + this.queueListingElement.on('queue', item => this.playGrouplikeItem(item)) + this.queueListingElement.on('space', item => this.handleSpacePressed()) this.queueListingElement.on('remove (backspace)', item => this.unqueueGrouplikeItem(item)) this.queueListingElement.on('remove (x)', item => this.unqueueGrouplikeItem(item)) this.queueListingElement.on('shuffle', () => this.shuffleQueue()) @@ -108,18 +107,9 @@ class AppElement extends FocusElement { this.tabber.addTab(grouplikeListing) this.tabber.selectTab(grouplikeListing) - const handleSelectFromMain = item => { - if (isGroup(item)) { - grouplikeListing.loadGrouplike(item) - } else { - this.playGrouplikeItem(item) - } - } - grouplikeListing.on('download', item => this.downloadGrouplikeItem(item)) - grouplikeListing.on('select (enter)', item => handleSelectFromMain(item)) - grouplikeListing.on('select (space)', item => this.handleSpacePressed( - () => handleSelectFromMain(item))) + grouplikeListing.on('browse', item => grouplikeListing.loadGrouplike(item)) + grouplikeListing.on('space', item => this.handleSpacePressed()) grouplikeListing.on('menu', (item, opts) => this.menu.show(opts)) grouplikeListing.on('queue', (item, {where = 'end', shuffle = false, play = false}) => { @@ -425,14 +415,11 @@ class AppElement extends FocusElement { this.queueListingElement.pathElement.showItem(null) } - handleSpacePressed(callback) { - // Pauses/resumes if a track is currently playing; otherwise, calls the - // callback function. + handleSpacePressed() { + // Pauses/resumes if a track is currently playing. if (this.playingTrack) { this.togglePause() - } else { - return callback() } } @@ -777,7 +764,7 @@ class GrouplikeListingElement extends FocusElement { if (this.grouplike.items.length) { for (const item of this.grouplike.items) { const itemElement = new GrouplikeItemElement(item, this.recordStore) - for (const evtName of ['download', 'remove (backspace)', 'remove (x)', 'mark', 'select (space)', 'select (enter)', 'queue', 'menu']) { + for (const evtName of ['download', 'remove (backspace)', 'remove (x)', 'mark', 'browse', 'space', 'queue', 'menu']) { itemElement.on(evtName, (...data) => this.emit(evtName, item, ...data)) } form.addInput(itemElement) @@ -948,9 +935,13 @@ class GrouplikeItemElement extends Button { } else if (telc.isCharacter(keyBuf, 'Q')) { this.emit('queue', {where: 'next'}) } else if (telc.isSpace(keyBuf)) { - this.emit('select (space)') + this.emit('space') } else if (telc.isEnter(keyBuf)) { - this.emit('select (enter)') + if (isGroup(this.item)) { + this.emit('browse') + } else { + this.emit('queue', {where: 'next', play: true}) + } } else if (telc.isBackspace(keyBuf)) { this.emit('remove (backspace)') } else if (telc.isCaselessLetter(keyBuf, 'x')) { |