« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/listRandomPageLinks.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/listRandomPageLinks.js')
-rw-r--r--src/content/dependencies/listRandomPageLinks.js62
1 files changed, 32 insertions, 30 deletions
diff --git a/src/content/dependencies/listRandomPageLinks.js b/src/content/dependencies/listRandomPageLinks.js
index 43bf7dd5..599a82d3 100644
--- a/src/content/dependencies/listRandomPageLinks.js
+++ b/src/content/dependencies/listRandomPageLinks.js
@@ -1,48 +1,51 @@
+import {empty} from '#sugar';
+
 export default {
   contentDependencies: [
     'generateListingPage',
+    'generateListRandomPageLinksAllAlbumsSection',
     'generateListRandomPageLinksGroupSection',
   ],
 
   extraDependencies: ['html', 'language', 'wikiData'],
 
-  sprawl({groupData}) {
-    return {groupData};
-  },
-
-  query(sprawl, spec) {
-    const group = directory =>
-      sprawl.groupData.find(group => group.directory === directory);
+  sprawl: ({wikiInfo}) => ({wikiInfo}),
 
-    return {
-      spec,
-      officialGroup: group('official'),
-      fandomGroup: group('fandom'),
-      beyondGroup: group('beyond'),
-    };
-  },
+  query: ({wikiInfo: {divideTrackListsByGroups: groups}}, spec) => ({
+    spec,
+    groups,
+    divideByGroups: !empty(groups),
+  }),
 
-  relations(relation, query) {
-    return {
-      page: relation('generateListingPage', query.spec),
+  relations: (relation, query) => ({
+    page: relation('generateListingPage', query.spec),
 
-      officialSection:
-        relation('generateListRandomPageLinksGroupSection', query.officialGroup),
+    allAlbumsSection:
+      (query.divideByGroups
+        ? null
+        : relation('generateListRandomPageLinksAllAlbumsSection')),
 
-      fandomSection:
-        relation('generateListRandomPageLinksGroupSection', query.fandomGroup),
-
-      beyondSection:
-        relation('generateListRandomPageLinksGroupSection', query.beyondGroup),
-    };
-  },
+    groupSections:
+      (query.divideByGroups
+        ? query.groups
+            .map(group => relation('generateListRandomPageLinksGroupSection', group))
+        : null),
+  }),
 
   generate(relations, {html, language}) {
     return relations.page.slots({
       type: 'custom',
       content: [
         html.tag('p',
-          language.$('listingPage.other.randomPages.chooseLinkLine')),
+          language.$('listingPage.other.randomPages.chooseLinkLine', {
+            fromPart:
+              (empty(relations.groupSections)
+                ? language.$('listingPage.other.randomPages.chooseLinkLine.fromPart.notDividedByGroups')
+                : language.$('listingPage.other.randomPages.chooseLinkLine.fromPart.dividedByGroups')),
+
+            browserSupportPart:
+              language.$('listingPage.other.randomPages.chooseLinkLine.browserSupportPart'),
+          })),
 
         html.tag('p',
           {class: 'js-hide-once-data'},
@@ -81,9 +84,8 @@ export default {
                   language.$('listingPage.other.randomPages.misc.randomTrackWholeSite'))),
             ])),
 
-          relations.officialSection,
-          relations.fandomSection,
-          relations.beyondSection,
+          relations.allAlbumsSection,
+          relations.groupSections,
         ]),
       ],
     });