« get me outta code hell

Only call buildItems once when a group is queued - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/ui.js
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-06-01 17:59:27 -0300
committerFlorrie <towerofnix@gmail.com>2018-06-01 17:59:27 -0300
commitc283c559c777eab7a533a38a646607a91e98bd6f (patch)
tree8fffe040476522b07d84f5d038d41a3b6810c664 /ui.js
parentb49395ccf3cf87dadc01fd4ba49ebdbda4cb15d4 (diff)
Only call buildItems once when a group is queued
Diffstat (limited to 'ui.js')
-rw-r--r--ui.js13
1 files changed, 7 insertions, 6 deletions
diff --git a/ui.js b/ui.js
index 778f5eb..0c2be5f 100644
--- a/ui.js
+++ b/ui.js
@@ -117,17 +117,17 @@ class AppElement extends FocusElement {
     this.player.togglePause()
   }
 
-  async queueGrouplikeItem(item, play = true, afterItem = null) {
+  async queueGrouplikeItem(topItem, play = true, afterItem = null) {
     const newTrackIndex = this.queueGrouplike.items.length
 
-    handleTrack: {
+    const recursivelyAddTracks = item => {
       // For groups, just queue all children.
       if (isGroup(item)) {
         for (const child of item.items) {
-          await this.queueGrouplikeItem(child, false)
+          recursivelyAddTracks(child)
         }
 
-        break handleTrack
+        return
       }
 
       const items = this.queueGrouplike.items
@@ -147,10 +147,11 @@ class AppElement extends FocusElement {
       } else {
         items.push(item)
       }
-
-      this.queueListingElement.buildItems()
     }
 
+    recursivelyAddTracks(topItem)
+    this.queueListingElement.buildItems()
+
     // This is the first new track, if a group was queued.
     const newTrack = this.queueGrouplike.items[newTrackIndex]
     if (play && !this.playingTrack && newTrack) {