« get me outta code hell

mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--playlist-utils.js12
-rw-r--r--todo.txt3
-rw-r--r--ui.js4
3 files changed, 12 insertions, 7 deletions
diff --git a/playlist-utils.js b/playlist-utils.js
index 6119bc3..de2c3f8 100644
--- a/playlist-utils.js
+++ b/playlist-utils.js
@@ -177,15 +177,17 @@ function flattenGrouplike(grouplike) {
   }
 }
 
-function countTotalItems(item) {
-  // Returns the total number of items in a grouplike, including items in any
+function countTotalTracks(item) {
+  // Returns the total number of tracks in a grouplike, including tracks in any
   // descendant groups. Basically the same as flattenGrouplike().items.length.
 
   if (isGroup(item)) {
-    return item.items.map(countTotalItems)
+    return item.items.map(countTotalTracks)
       .reduce((a, b) => a + b, 0)
-  } else {
+  } else if (isTrack(item)) {
     return 1
+  } else {
+    return 0
   }
 }
 
@@ -603,7 +605,7 @@ module.exports = {
   updatePlaylistFormat, updateGroupFormat, updateTrackFormat,
   cloneGrouplike,
   filterTracks,
-  flattenGrouplike, countTotalItems,
+  flattenGrouplike, countTotalTracks,
   shuffleOrderOfGroups,
   reverseOrderOfGroups,
   partiallyFlattenGrouplike, collapseGrouplike,
diff --git a/todo.txt b/todo.txt
index 0eca376..891479a 100644
--- a/todo.txt
+++ b/todo.txt
@@ -436,3 +436,6 @@ TODO: A "play (in new player)" option in the play menu. It'd be nice to have
 
 TODO: "Shuffle queue", "shuffle these tracks" options in the queue's
       context menu?
+
+TODO: It looks like you can't move the currently playing track by re-queuing
+      it? Investigate this.
diff --git a/ui.js b/ui.js
index 9a61ec4..03337f5 100644
--- a/ui.js
+++ b/ui.js
@@ -13,7 +13,7 @@ const {
 
 const {
   cloneGrouplike,
-  countTotalItems,
+  countTotalTracks,
   flattenGrouplike,
   getItemPath,
   getNameWithoutTrackNumber,
@@ -882,7 +882,7 @@ class AppElement extends FocusElement {
         canControlQueue && {label: 'Remove from queue', action: () => this.unqueue(item)}
       ]
     } else {
-      const numTracks = countTotalItems(item)
+      const numTracks = countTotalTracks(item)
       const { string: durationString } = this.backend.getDuration(item)
       items = [
         // A label that just shows some brief information about the item.