« get me outta code hell

content: gAIPTracksChunkedList: stub separate-components refactor - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateArtistInfoPageTracksChunk.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-03-06 17:01:02 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-06-18 22:56:02 -0300
commitab98a1f8ea4c5d14e76d88e8ac2992b062e7e154 (patch)
treebd91e0f223c3494df9ce43ec46f1587af55c764b /src/content/dependencies/generateArtistInfoPageTracksChunk.js
parent5db0e13f3a70612b453124c0d00a4933c4d24b88 (diff)
content: gAIPTracksChunkedList: stub separate-components refactor
Diffstat (limited to 'src/content/dependencies/generateArtistInfoPageTracksChunk.js')
-rw-r--r--src/content/dependencies/generateArtistInfoPageTracksChunk.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/content/dependencies/generateArtistInfoPageTracksChunk.js b/src/content/dependencies/generateArtistInfoPageTracksChunk.js
new file mode 100644
index 00000000..b27a2988
--- /dev/null
+++ b/src/content/dependencies/generateArtistInfoPageTracksChunk.js
@@ -0,0 +1,52 @@
+import {stitchArrays} from '#sugar';
+import {getTotalDuration} from '#wiki-data';
+
+export default {
+  contentDependencies: [
+    'generateArtistInfoPageChunk',
+    'generateArtistInfoPageTracksChunkItem',
+    'linkAlbum',
+  ],
+
+  relations: (relation, artist, album, tracks, contribs) => ({
+    template:
+      relation('generateArtistInfoPageChunk'),
+
+    albumLink:
+      relation('linkAlbum', album),
+
+    items:
+      stitchArrays({
+        track: tracks,
+        contribs: contribs,
+      }).map(({track, contribs}) =>
+          relation('generateArtistInfoPageTracksChunkItem',
+            artist,
+            track,
+            contribs)),
+  }),
+
+  data: (_artist, album, tracks, _contribs) => ({
+    // STUB: This is flat-out incorrect date behavior.
+    date:
+      album.date,
+
+    duration:
+      getTotalDuration(tracks, {originalReleasesOnly: true}),
+
+    durationApproximate:
+      tracks
+        .filter(track => track.duration && track.isOriginalRelease)
+        .length > 1,
+  }),
+
+  generate: (data, relations) =>
+    relations.template.slots({
+      mode: 'album',
+      albumLink: relations.albumLink,
+      date: data.date,
+      duration: data.duration,
+      durationApproximate: data.durationApproximate,
+      items: relations.items,
+    }),
+};