« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/content/dependencies/generateListRandomPageLinksGroupSection.js9
-rw-r--r--src/content/dependencies/listRandomPageLinks.js28
-rw-r--r--src/static/client2.js45
3 files changed, 54 insertions, 28 deletions
diff --git a/src/content/dependencies/generateListRandomPageLinksGroupSection.js b/src/content/dependencies/generateListRandomPageLinksGroupSection.js
index 2a684b19..74872724 100644
--- a/src/content/dependencies/generateListRandomPageLinksGroupSection.js
+++ b/src/content/dependencies/generateListRandomPageLinksGroupSection.js
@@ -23,10 +23,7 @@ export default {
         .map(() => relation('generateColorStyleVariables')),
   }),
 
-  data: (query, sprawl, group) => ({
-    groupDirectory:
-      group.directory,
-
+  data: (query) => ({
     albumColors:
       query.albums
         .map(album => album.color),
@@ -48,12 +45,12 @@ export default {
 
           randomAlbum:
             html.tag('a',
-              {href: '#', 'data-random': 'album-in-' + data.groupDirectory},
+              {href: '#', 'data-random': 'album-in-group-dl'},
               language.$('listingPage.other.randomPages.group.randomAlbum')),
 
           randomTrack:
             html.tag('a',
-              {href: '#', 'data-random': 'track-in-' + data.groupDirectory},
+              {href: '#', 'data-random': 'track-in-group-dl'},
               language.$('listingPage.other.randomPages.group.randomTrack')),
         })),
 
diff --git a/src/content/dependencies/listRandomPageLinks.js b/src/content/dependencies/listRandomPageLinks.js
index 43bf7dd5..57ecb044 100644
--- a/src/content/dependencies/listRandomPageLinks.js
+++ b/src/content/dependencies/listRandomPageLinks.js
@@ -6,19 +6,16 @@ export default {
 
   extraDependencies: ['html', 'language', 'wikiData'],
 
-  sprawl({groupData}) {
-    return {groupData};
+  sprawl({wikiInfo}) {
+    return {wikiInfo};
   },
 
   query(sprawl, spec) {
-    const group = directory =>
-      sprawl.groupData.find(group => group.directory === directory);
-
     return {
       spec,
-      officialGroup: group('official'),
-      fandomGroup: group('fandom'),
-      beyondGroup: group('beyond'),
+
+      groups:
+        sprawl.wikiInfo.divideTrackListsByGroups,
     };
   },
 
@@ -26,14 +23,9 @@ export default {
     return {
       page: relation('generateListingPage', query.spec),
 
-      officialSection:
-        relation('generateListRandomPageLinksGroupSection', query.officialGroup),
-
-      fandomSection:
-        relation('generateListRandomPageLinksGroupSection', query.fandomGroup),
-
-      beyondSection:
-        relation('generateListRandomPageLinksGroupSection', query.beyondGroup),
+      groupSections:
+        query.groups
+          .map(group => relation('generateListRandomPageLinksGroupSection', group)),
     };
   },
 
@@ -81,9 +73,7 @@ export default {
                   language.$('listingPage.other.randomPages.misc.randomTrackWholeSite'))),
             ])),
 
-          relations.officialSection,
-          relations.fandomSection,
-          relations.beyondSection,
+          relations.groupSections,
         ]),
       ],
     });
diff --git a/src/static/client2.js b/src/static/client2.js
index 758d91a6..3a5f9c37 100644
--- a/src/static/client2.js
+++ b/src/static/client2.js
@@ -149,6 +149,47 @@ function addRandomLinkListeners() {
           a.href = openAlbum(pick(albumData).directory);
           break;
 
+        case 'track':
+          a.href = openTrack(getRefDirectory(pick(tracks(albumData))));
+          break;
+
+        case 'album-in-group-dl': {
+          const albumLinks =
+            Array.from(a
+              .closest('dt')
+              .nextElementSibling
+              .querySelectorAll('li a'))
+
+          const albumDirectories =
+            albumLinks.map(a =>
+              getComputedStyle(a).getPropertyValue('--album-directory'));
+
+          a.href = openAlbum(pick(albumDirectories));
+          break;
+        }
+
+        case 'track-in-group-dl': {
+          const albumLinks =
+            Array.from(a
+              .closest('dt')
+              .nextElementSibling
+              .querySelectorAll('li a'))
+
+          const albumDirectories =
+            albumLinks.map(a =>
+              getComputedStyle(a).getPropertyValue('--album-directory'));
+
+          const filteredAlbumData =
+            albumData.filter(album =>
+              albumDirectories.includes(album.directory));
+
+          a.href = openTrack(getRefDirectory(pick(tracks(filteredAlbumData))));
+          break;
+        }
+
+        /* Legacy links, for old versions             *
+         * of generateListRandomPageLinksGroupSection */
+
         case 'album-in-official':
           a.href = openAlbum(pick(officialAlbumData).directory);
           break;
@@ -161,9 +202,7 @@ function addRandomLinkListeners() {
           a.href = openAlbum(pick(beyondAlbumData).directory);
           break;
 
-        case 'track':
-          a.href = openTrack(getRefDirectory(pick(tracks(albumData))));
-          break;
+        /* End legacy links */
 
         case 'track-in-album':
           a.href = openTrack(getRefDirectory(pick(getAlbum(a).tracks)));