« get me outta code hell

content: generateTrackList: blank if no tracks - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-06-12 13:16:39 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-06-18 22:56:07 -0300
commit79ac807130a48578cf32b1b2258c481121a1c7c7 (patch)
tree19cd16f5b19e477d50655df9b992c7255f50aef4 /src
parent8928793a9683e742985c744c93f623d04a645d49 (diff)
content: generateTrackList: blank if no tracks
Diffstat (limited to 'src')
-rw-r--r--src/content/dependencies/generateTrackList.js80
1 files changed, 36 insertions, 44 deletions
diff --git a/src/content/dependencies/generateTrackList.js b/src/content/dependencies/generateTrackList.js
index 3c36d248..4760ff2f 100644
--- a/src/content/dependencies/generateTrackList.js
+++ b/src/content/dependencies/generateTrackList.js
@@ -5,55 +5,47 @@ export default {
 
   extraDependencies: ['html', 'language'],
 
-  relations(relation, tracks) {
-    if (empty(tracks)) {
-      return {};
-    }
+  relations: (relation, tracks) => ({
+    trackLinks:
+      tracks
+        .map(track => relation('linkTrack', track)),
 
-    return {
-      trackLinks:
-        tracks
-          .map(track => relation('linkTrack', track)),
-
-      contributionLinks:
-        tracks
-          .map(track =>
-            (empty(track.artistContribs)
-              ? null
-              : track.artistContribs
-                  .map(contrib => relation('linkContribution', contrib)))),
-    };
-  },
+    contributionLinks:
+      tracks
+        .map(track =>
+          track.artistContribs
+            .map(contrib => relation('linkContribution', contrib))),
+  }),
 
   slots: {
     showContribution: {type: 'boolean', default: false},
     showIcons: {type: 'boolean', default: false},
   },
 
-  generate(relations, slots, {html, language}) {
-    return (
-      html.tag('ul',
-        stitchArrays({
-          trackLink: relations.trackLinks,
-          contributionLinks: relations.contributionLinks,
-        }).map(({trackLink, contributionLinks}) =>
-            html.tag('li',
-              (empty(contributionLinks)
-                ? trackLink
-                : language.$('trackList.item.withArtists', {
-                    track: trackLink,
-                    by:
-                      html.tag('span', {class: 'by'},
-                        html.metatag('chunkwrap', {split: ','},
-                          language.$('trackList.item.withArtists.by', {
-                            artists:
-                              language.formatConjunctionList(
-                                contributionLinks.map(link =>
-                                  link.slots({
-                                    showContribution: slots.showContribution,
-                                    showIcons: slots.showIcons,
-                                  }))),
-                          }))),
-                  }))))));
-  },
+  generate: (relations, slots, {html, language}) =>
+    html.tag('ul',
+      {[html.onlyIfContent]: true},
+
+      stitchArrays({
+        trackLink: relations.trackLinks,
+        contributionLinks: relations.contributionLinks,
+      }).map(({trackLink, contributionLinks}) =>
+          html.tag('li',
+            (empty(contributionLinks)
+              ? trackLink
+              : language.$('trackList.item.withArtists', {
+                  track: trackLink,
+                  by:
+                    html.tag('span', {class: 'by'},
+                      html.metatag('chunkwrap', {split: ','},
+                        language.$('trackList.item.withArtists.by', {
+                          artists:
+                            language.formatConjunctionList(
+                              contributionLinks.map(link =>
+                                link.slots({
+                                  showContribution: slots.showContribution,
+                                  showIcons: slots.showIcons,
+                                }))),
+                        }))),
+                }))))),
 };