« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/data/things/track.js40
-rw-r--r--src/page/album.js17
2 files changed, 53 insertions, 4 deletions
diff --git a/src/data/things/track.js b/src/data/things/track.js
index 0842bf23..880f65fe 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -187,6 +187,26 @@ export class Track extends Thing {
       },
     },
 
+    hasUniqueCoverArt: {
+      flags: {expose: true},
+
+      expose: {
+        dependencies: ['albumData', 'coverArtistContribsByRef', 'hasCoverArt'],
+        compute: ({
+          albumData,
+          coverArtistContribsByRef,
+          hasCoverArt,
+          [Track.instance]: track,
+        }) =>
+          Track.hasUniqueCoverArt(
+            track,
+            albumData,
+            coverArtistContribsByRef,
+            hasCoverArt
+          ),
+      },
+    },
+
     originalReleaseTrack: Thing.common.dynamicThingFromSingleReference(
       'originalReleaseTrackByRef',
       'trackData',
@@ -324,6 +344,26 @@ export class Track extends Thing {
     true
   );
 
+  // Now this is a doozy!
+  static hasUniqueCoverArt(
+    track,
+    albumData,
+    coverArtistContribsByRef,
+    hasCoverArt
+  ) {
+    if (coverArtistContribsByRef?.length > 0) {
+      return true;
+    } else if (coverArtistContribsByRef) {
+      return false;
+    } else if (hasCoverArt === false) {
+      return false;
+    } else if (Track.findAlbum(track, albumData)?.hasTrackArt) {
+      return true;
+    } else {
+      return false;
+    }
+  }
+
   [inspect.custom]() {
     const base = Thing.prototype[inspect.custom].apply(this);
 
diff --git a/src/page/album.js b/src/page/album.js
index fb738db8..28c09907 100644
--- a/src/page/album.js
+++ b/src/page/album.js
@@ -416,13 +416,22 @@ export function write(album, {wikiData}) {
           html.tag('div',
             {class: 'grid-listing'},
             getGridHTML({
-              srcFn: t => t.album ? getTrackCover(t) : getAlbumCover(t),
               linkFn: (t, opts) => t.album ? link.track(t, opts) : link.album(t, opts),
               noSrcTextFn: t =>
                 language.$('misc.albumGalleryGrid.noCoverArt', {
                   name: t.name,
                 }),
 
+              srcFn(t) {
+                if (!t.album) {
+                  return getAlbumCover(t);
+                } else if (t.hasUniqueCoverArt) {
+                  return getTrackCover(t);
+                } else {
+                  return null;
+                }
+              },
+
               entries: [
                 // {item: album},
                 ...album.tracks.map(track => ({item: track})),
@@ -641,12 +650,12 @@ export function generateAlbumSecondaryNav(album, currentTrack, {
   };
 }
 
-function checkGalleryPage(_album) {
-  return true;
+function checkGalleryPage(album) {
+  return album.tracks.some(t => t.hasUniqueCoverArt);
 }
 
 function checkCommentaryPage(album) {
-  return !empty([album, ...album.tracks].filter((x) => x.commentary));
+  return !!album.commentary || album.tracks.some(t => t.commentary);
 }
 
 export function generateAlbumNavLinks(album, currentTrack, {