From b18eebf056b69fe46d7c980454b8ea95132b2e7e Mon Sep 17 00:00:00 2001 From: Florrie Date: Mon, 30 Jul 2018 19:12:25 -0300 Subject: Clean up select code --- ui.js | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) (limited to 'ui.js') 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')) { -- cgit 1.3.0-6-gf8a5