« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateAlbumTrackListItem.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/generateAlbumTrackListItem.js')
-rw-r--r--src/content/dependencies/generateAlbumTrackListItem.js155
1 files changed, 38 insertions, 117 deletions
diff --git a/src/content/dependencies/generateAlbumTrackListItem.js b/src/content/dependencies/generateAlbumTrackListItem.js
index 851bf32e..a42dcb66 100644
--- a/src/content/dependencies/generateAlbumTrackListItem.js
+++ b/src/content/dependencies/generateAlbumTrackListItem.js
@@ -1,74 +1,36 @@
-import {compareArrays, empty} from '#sugar';
-
 export default {
-  contentDependencies: [
-    'generateAlbumTrackListMissingDuration',
-    'generateArtistCredit',
-    'linkTrack',
-  ],
-
-  extraDependencies: ['getColors', 'html', 'language'],
-
-  query(track, album) {
-    const query = {};
-
-    query.duration = track.duration ?? 0;
+  contentDependencies: ['generateTrackListItem'],
+  extraDependencies: ['html'],
 
-    query.trackHasDuration = !!track.duration;
+  query: (track, album) => ({
+    trackHasDuration:
+      !!track.duration,
 
-    query.sectionHasDuration =
+    sectionHasDuration:
       !album.trackSections
         .some(section =>
           section.tracks.every(track => !track.duration) &&
-          section.tracks.includes(track));
-
-    query.albumHasDuration =
-      album.tracks.some(track => track.duration);
-
-    return query;
-  },
-
-  relations(relation, query, track) {
-    const relations = {};
-
-    relations.credit =
-      relation('generateArtistCredit',
-        track.artistContribs,
-        track.album.artistContribs);
-
-    relations.trackLink =
-      relation('linkTrack', track);
-
-    if (!query.trackHasDuration) {
-      relations.missingDuration =
-        relation('generateAlbumTrackListMissingDuration');
-    }
-
-    return relations;
-  },
+          section.tracks.includes(track)),
 
-  data(query, track, album) {
-    const data = {};
+    albumHasDuration:
+      album.tracks.some(track => track.duration),
+  }),
 
-    data.duration = query.duration;
-    data.trackHasDuration = query.trackHasDuration;
-    data.sectionHasDuration = query.sectionHasDuration;
-    data.albumHasDuration = query.albumHasDuration;
+  relations: (relation, query, track) => ({
+    item:
+      relation('generateTrackListItem',
+        track,
+        track.album.artistContribs),
+  }),
 
-    if (track.color !== album.color) {
-      data.color = track.color;
-    }
+  data: (query, track, album) => ({
+    trackHasDuration: query.trackHasDuration,
+    sectionHasDuration: query.sectionHasDuration,
+    albumHasDuration: query.albumHasDuration,
 
-    data.showArtists =
-      !empty(track.artistContribs) &&
-       (empty(album.artistContribs) ||
-        !compareArrays(
-          track.artistContribs.map(contrib => contrib.artist),
-          album.artistContribs.map(contrib => contrib.artist),
-          {checkOrder: false}));
-
-    return data;
-  },
+    colorize:
+      track.color !== album.color,
+  }),
 
   slots: {
     collapseDurationScope: {
@@ -79,60 +41,19 @@ export default {
     },
   },
 
-  generate: (data, relations, slots, {getColors, html, language}) =>
-    language.encapsulate('trackList.item', itemCapsule =>
-      html.tag('li',
-        data.color &&
-          {style: `--primary-color: ${getColors(data.color).primary}`},
-
-        language.encapsulate(itemCapsule, workingCapsule => {
-          const workingOptions = {};
-
-          workingOptions.track =
-            relations.trackLink
-              .slot('color', false);
-
-          const collapseDuration =
-            (slots.collapseDurationScope === 'track'
-              ? !data.trackHasDuration
-           : slots.collapseDurationScope === 'section'
-              ? !data.sectionHasDuration
-           : slots.collapseDurationScope === 'album'
-              ? !data.albumHasDuration
-              : false);
-
-          if (!collapseDuration) {
-            workingCapsule += '.withDuration';
-            workingOptions.duration =
-              (data.trackHasDuration
-                ? language.$(itemCapsule, 'withDuration.duration', {
-                    duration:
-                      language.formatDuration(data.duration),
-                  })
-                : relations.missingDuration);
-          }
-
-          const artistCapsule = language.encapsulate(itemCapsule, 'withArtists');
-
-          relations.credit.setSlots({
-            normalStringKey:
-              artistCapsule + '.by',
-
-            featuringStringKey:
-              artistCapsule + '.featuring',
-
-            normalFeaturingStringKey:
-              artistCapsule + '.by.featuring',
-          });
-
-          if (!html.isBlank(relations.credit)) {
-            workingCapsule += '.withArtists';
-            workingOptions.by =
-              html.tag('span', {class: 'by'},
-                html.metatag('chunkwrap', {split: ','},
-                  html.resolve(relations.credit)));
-          }
-
-          return language.$(workingCapsule, workingOptions);
-        }))),
+  generate: (data, relations, slots) =>
+    relations.item.slots({
+      showArtists: true,
+
+      showDuration:
+        (slots.collapseDurationScope === 'track'
+          ? data.trackHasDuration
+       : slots.collapseDurationScope === 'section'
+          ? data.sectionHasDuration
+       : slots.collapseDurationScope === 'album'
+          ? data.albumHasDuration
+          : true),
+
+      color: data.colorize,
+    }),
 };