« get me outta code hell

content: generateAlbumNavAccent: update internals + use dots - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateAlbumNavAccent.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-08-14 12:25:27 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-11-02 22:25:45 -0300
commitfa950223d7f9531d1c4dbf3fa1235743196d2a84 (patch)
treef9773998c4506aa1452eb60b09b1ee2f1988c420 /src/content/dependencies/generateAlbumNavAccent.js
parent7833e72b7bdac1a67aae038f3a1c2d6842441d4c (diff)
content: generateAlbumNavAccent: update internals + use dots
Diffstat (limited to 'src/content/dependencies/generateAlbumNavAccent.js')
-rw-r--r--src/content/dependencies/generateAlbumNavAccent.js158
1 files changed, 93 insertions, 65 deletions
diff --git a/src/content/dependencies/generateAlbumNavAccent.js b/src/content/dependencies/generateAlbumNavAccent.js
index 4b6fb062..e5b3a23d 100644
--- a/src/content/dependencies/generateAlbumNavAccent.js
+++ b/src/content/dependencies/generateAlbumNavAccent.js
@@ -1,8 +1,10 @@
-import {empty} from '#sugar';
+import {atOffset} from '#sugar';
 
 export default {
   contentDependencies: [
-    'generatePreviousNextLinks',
+    'generateInterpageDotSwitcher',
+    'generateNextLink',
+    'generatePreviousLink',
     'linkTrack',
     'linkAlbumCommentary',
     'linkAlbumGallery',
@@ -10,47 +12,70 @@ export default {
 
   extraDependencies: ['html', 'language'],
 
-  relations(relation, album, track) {
-    const relations = {};
+  query(album, track) {
+    const query = {};
 
-    relations.previousNextLinks =
-      relation('generatePreviousNextLinks');
+    const index =
+      (track
+        ? album.tracks.indexOf(track)
+        : null);
 
-    relations.previousTrackLink = null;
-    relations.nextTrackLink = null;
+    query.previousTrack =
+      (track
+        ? atOffset(album.tracks, index, -1)
+        : null);
 
-    if (track) {
-      const index = album.tracks.indexOf(track);
+    query.nextTrack =
+      (track
+        ? atOffset(album.tracks, index, +1)
+        : null);
 
-      if (index > 0) {
-        relations.previousTrackLink =
-          relation('linkTrack', album.tracks[index - 1]);
-      }
+    query.albumHasAnyCommentary =
+      !!(album.commentary ||
+         album.tracks.some(t => t.commentary));
 
-      if (index < album.tracks.length - 1) {
-        relations.nextTrackLink =
-          relation('linkTrack', album.tracks[index + 1]);
-      }
-    }
+    return query;
+  },
 
-    relations.albumGalleryLink =
-      relation('linkAlbumGallery', album);
+  relations: (relation, query, album, _track) => ({
+    switcher:
+      relation('generateInterpageDotSwitcher'),
 
-    if (album.commentary || album.tracks.some(t => t.commentary)) {
-      relations.albumCommentaryLink =
-        relation('linkAlbumCommentary', album);
-    }
+    previousLink:
+      relation('generatePreviousLink'),
 
-    return relations;
-  },
+    nextLink:
+      relation('generateNextLink'),
 
-  data(album, track) {
-    return {
-      hasMultipleTracks: album.tracks.length > 1,
-      galleryIsStub: album.tracks.every(t => !t.hasUniqueCoverArt),
-      isTrackPage: !!track,
-    };
-  },
+    previousTrackLink:
+      (query.previousTrack
+        ? relation('linkTrack', query.previousTrack)
+        : null),
+
+    nextTrackLink:
+      (query.nextTrack
+        ? relation('linkTrack', query.nextTrack)
+        : null),
+
+    albumGalleryLink:
+      relation('linkAlbumGallery', album),
+
+    albumCommentaryLink:
+      (query.albumHasAnyCommentary
+        ? relation('linkAlbumCommentary', album)
+        : null),
+  }),
+
+  data: (query, album, track) => ({
+    hasMultipleTracks:
+      album.tracks.length > 1,
+
+    galleryIsStub:
+      album.tracks.every(t => !t.hasUniqueCoverArt),
+
+    isTrackPage:
+      !!track,
+  }),
 
   slots: {
     showTrackNavigation: {type: 'boolean', default: false},
@@ -65,32 +90,28 @@ export default {
     const albumNavCapsule = language.encapsulate('albumPage.nav');
     const trackNavCapsule = language.encapsulate('trackPage.nav');
 
-    const {content: extraLinks = []} =
-      slots.showExtraLinks &&
-        {content: [
-          (!data.galleryIsStub || slots.currentExtra === 'gallery') &&
-            relations.albumGalleryLink?.slots({
-              attributes: {class: slots.currentExtra === 'gallery' && 'current'},
-              content: language.$(albumNavCapsule, 'gallery'),
-            }),
-
-          relations.albumCommentaryLink?.slots({
-            attributes: {class: slots.currentExtra === 'commentary' && 'current'},
-            content: language.$(albumNavCapsule, 'commentary'),
-          }),
-        ]};
-
-    const {content: previousNextLinks = []} =
-      slots.showTrackNavigation &&
+    const previousLink =
       data.isTrackPage &&
-      data.hasMultipleTracks &&
-        relations.previousNextLinks.slots({
-          previousLink: relations.previousTrackLink,
-          nextLink: relations.nextTrackLink,
+        relations.previousLink.slot('link', relations.previousTrackLink);
+
+    const nextLink =
+      data.isTrackPage &&
+        relations.nextLink.slot('link', relations.nextTrackLink);
+
+    const galleryLink =
+      (!data.galleryIsStub || slots.currentExtra === 'gallery') &&
+        relations.albumGalleryLink.slots({
+          attributes: {class: slots.currentExtra === 'gallery' && 'current'},
+          content: language.$(albumNavCapsule, 'gallery'),
         });
 
+    const commentaryLink =
+      relations.albumCommentaryLink?.slots({
+        attributes: {class: slots.currentExtra === 'commentary' && 'current'},
+        content: language.$(albumNavCapsule, 'commentary'),
+      });
+
     const randomLink =
-      slots.showTrackNavigation &&
       data.hasMultipleTracks &&
         html.tag('a',
           {id: 'random-button'},
@@ -100,16 +121,23 @@ export default {
             ? language.$(trackNavCapsule, 'random')
             : language.$(albumNavCapsule, 'randomTrack')));
 
-    const allLinks = [
-      ...previousNextLinks,
-      ...extraLinks,
-      randomLink,
-    ].filter(Boolean);
+    return relations.switcher.slots({
+      links: [
+        slots.showTrackNavigation &&
+          previousLink,
+
+        slots.showTrackNavigation &&
+          nextLink,
+
+        slots.showExtraLinks &&
+          galleryLink,
 
-    if (empty(allLinks)) {
-      return html.blank();
-    }
+        slots.showExtraLinks &&
+          commentaryLink,
 
-    return `(${language.formatUnitList(allLinks)})`;
+        slots.showTrackNavigation &&
+          randomLink,
+      ],
+    });
   },
 };