« get me outta code hell

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:
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) {