« get me outta code hell

content: misc. changes, groups divided by tracks, relation sections - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/util
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-04-18 21:09:10 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-04-18 21:09:10 -0300
commit7eda6868381e9e145d503294837f6f60de7e38e0 (patch)
treed7b5b03557549066562a95f5422a1b9251f2513f /src/content/util
parentc504e1dd0497edc694bd594052728ffb39af70a8 (diff)
content: misc. changes, groups divided by tracks, relation sections
Diffstat (limited to 'src/content/util')
-rw-r--r--src/content/util/groupTracksByGroup.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/content/util/groupTracksByGroup.js b/src/content/util/groupTracksByGroup.js
new file mode 100644
index 00000000..bae2c8c5
--- /dev/null
+++ b/src/content/util/groupTracksByGroup.js
@@ -0,0 +1,23 @@
+import {empty} from '../../util/sugar.js';
+
+export default function groupTracksByGroup(tracks, groups) {
+  const lists = new Map(groups.map(group => [group, []]));
+  lists.set('other', []);
+
+  for (const track of tracks) {
+    const group = groups.find(group => group.albums.includes(track.album));
+    if (group) {
+      lists.get(group).push(track);
+    } else {
+      other.get('other').push(track);
+    }
+  }
+
+  for (const [key, tracks] of lists.entries()) {
+    if (empty(tracks)) {
+      lists.delete(key);
+    }
+  }
+
+  return lists;
+}