From 91136e5a3fedaa7c33d4df00b7e64829b5419157 Mon Sep 17 00:00:00 2001
From: "(quasar) nebula" <qznebula@protonmail.com>
Date: Sun, 6 Aug 2023 17:55:06 -0300
Subject: content: generateArtistInfoPageTracksChunkedList: handle "as artist
 and contributor" gracefully

---
 .../generateArtistInfoPageTracksChunkedList.js     | 35 ++++++++++++++++++----
 1 file changed, 30 insertions(+), 5 deletions(-)

(limited to 'src/content/dependencies')

diff --git a/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js b/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js
index d6ae9ae8..6c953f1a 100644
--- a/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js
+++ b/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js
@@ -19,8 +19,30 @@ export default {
   extraDependencies: ['language'],
 
   query(artist) {
+    const tracksAsArtistAndContributor =
+      artist.tracksAsArtist
+        .filter(track => artist.tracksAsContributor.includes(track));
+
+    const tracksAsArtistOnly =
+      artist.tracksAsArtist
+        .filter(track => !artist.tracksAsContributor.includes(track));
+
+    const tracksAsContributorOnly =
+      artist.tracksAsContributor
+        .filter(track => !artist.tracksAsArtist.includes(track));
+
     const entries = [
-      ...artist.tracksAsArtist.map(track => ({
+      ...tracksAsArtistAndContributor.map(track => ({
+        thing: track,
+        entry: {
+          track,
+          album: track.album,
+          date: track.date,
+          contribs: [...track.artistContribs, ...track.contributorContribs],
+        },
+      })),
+
+      ...tracksAsArtistOnly.map(track => ({
         thing: track,
         entry: {
           track,
@@ -30,7 +52,7 @@ export default {
         },
       })),
 
-      ...artist.tracksAsContributor.map(track => ({
+      ...tracksAsContributorOnly.map(track => ({
         thing: track,
         entry: {
           track,
@@ -102,8 +124,9 @@ export default {
         query.chunks.map(({chunk}) =>
           chunk.map(({contribs}) =>
             contribs
-              .find(({who}) => who === artist)
-              .what)),
+              .filter(({who}) => who === artist)
+              .filter(({what}) => what)
+              .map(({what}) => what))),
 
       trackRereleases:
         query.chunks.map(({chunk}) =>
@@ -166,9 +189,11 @@ export default {
                   }) =>
                     item.slots({
                       otherArtistLinks,
-                      contribution,
                       rerelease,
 
+                      contribution:
+                        language.formatUnitList(contribution),
+
                       content:
                         (duration
                           ? language.$('artistPage.creditList.entry.track.withDuration', {
-- 
cgit 1.3.0-6-gf8a5