« get me outta code hell

content: generateAlbumTrackList: general style cleanup - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-02-06 17:35:07 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-02-10 13:31:05 -0400
commitb451bcdea910c463f63bb2d1f9293d3f91aa1914 (patch)
tree910836dda98cec20a6aea4d4a5dcde8a1c83f161
parent694dd3ccd0ce447b3ebab6f1a65585206b4b69fc (diff)
content: generateAlbumTrackList: general style cleanup
-rw-r--r--src/content/dependencies/generateAlbumTrackList.js68
1 files changed, 45 insertions, 23 deletions
diff --git a/src/content/dependencies/generateAlbumTrackList.js b/src/content/dependencies/generateAlbumTrackList.js
index 40cbb14d..3186306a 100644
--- a/src/content/dependencies/generateAlbumTrackList.js
+++ b/src/content/dependencies/generateAlbumTrackList.js
@@ -53,7 +53,7 @@ export default {
           album.trackSections.map(() =>
             relation('generateContentHeading'));
 
-        relations.itemsByTrackSection =
+        relations.trackSectionItems =
           album.trackSections.map(section =>
             section.tracks.map(track =>
               relation('generateAlbumTrackListItem', track, album)));
@@ -61,9 +61,10 @@ export default {
         break;
 
       case 'tracks':
-        relations.itemsByTrack =
+        relations.items =
           album.tracks.map(track =>
             relation('generateAlbumTrackListItem', track, album));
+
         break;
     }
 
@@ -78,20 +79,29 @@ export default {
 
     switch (query.displayMode) {
       case 'trackSections':
-        data.trackSectionInfo =
-          album.trackSections.map(section => {
-            const info = {};
-
-            info.name = section.name;
-            info.duration = accumulateSum(section.tracks, track => track.duration);
-            info.durationApproximate = section.tracks.length > 1;
-
-            if (album.hasTrackNumbers) {
-              info.startIndex = section.startIndex;
-            }
+        data.trackSectionNames =
+          album.trackSections
+            .map(section => section.name);
+
+        data.trackSectionDurations =
+          album.trackSections
+            .map(section =>
+              accumulateSum(section.tracks, track => track.duration));
+
+        data.trackSectionDurationsApproximate =
+          album.trackSections
+            .map(section => section.tracks.length > 1);
+
+        if (album.hasTrackNumbers) {
+          data.trackSectionStartIndices =
+            album.trackSections
+              .map(section => section.startIndex);
+        } else {
+          data.trackSectionStartIndices =
+            album.trackSections
+              .map(() => null);
+        }
 
-            return info;
-          });
         break;
     }
 
@@ -106,17 +116,29 @@ export default {
         return html.tag('dl', {class: 'album-group-list'},
           stitchArrays({
             heading: relations.trackSectionHeadings,
-            items: relations.itemsByTrackSection,
-            info: data.trackSectionInfo,
-          }).map(({heading, items, info}) => [
+            items: relations.trackSectionItems,
+
+            name: data.trackSectionNames,
+            duration: data.trackSectionDurations,
+            durationApproximate: data.trackSectionDurationsApproximate,
+            startIndex: data.trackSectionStartIndices,
+          }).map(({
+              heading,
+              items,
+
+              name,
+              duration,
+              durationApproximate,
+              startIndex,
+            }) => [
               heading.slots({
                 tag: 'dt',
                 title:
                   language.$('trackList.section.withDuration', {
-                    section: info.name,
+                    section: name,
                     duration:
-                      language.formatDuration(info.duration, {
-                        approximate: info.durationApproximate,
+                      language.formatDuration(duration, {
+                        approximate: durationApproximate,
                       }),
                   }),
               }),
@@ -124,13 +146,13 @@ export default {
               html.tag('dd',
                 html.tag(listTag,
                   data.hasTrackNumbers &&
-                    {start: info.startIndex + 1},
+                    {start: startIndex + 1},
 
                   items)),
             ]));
 
       case 'tracks':
-        return html.tag(listTag, relations.itemsByTrack);
+        return html.tag(listTag, relations.items);
 
       default:
         return html.blank();