« 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
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies')
-rw-r--r--src/content/dependencies/generateChronologyLinks.js7
-rw-r--r--src/content/dependencies/generateTrackChronologyLinks.js46
2 files changed, 39 insertions, 14 deletions
diff --git a/src/content/dependencies/generateChronologyLinks.js b/src/content/dependencies/generateChronologyLinks.js
index 19c33be6..b769a5aa 100644
--- a/src/content/dependencies/generateChronologyLinks.js
+++ b/src/content/dependencies/generateChronologyLinks.js
@@ -4,6 +4,11 @@ export default {
   extraDependencies: ['html', 'language'],
 
   slots: {
+    allowCollapsing: {
+      type: 'boolean',
+      default: true,
+    },
+
     showOnly: {
       type: 'boolean',
       default: false,
@@ -52,7 +57,7 @@ export default {
       return html.blank();
     }
 
-    if (totalContributionCount > 8) {
+    if (slots.allowCollapsing && totalContributionCount > 8) {
       return html.tag('div', {class: 'chronology'},
         language.$('misc.chronology.seeArtistPages'));
     }
diff --git a/src/content/dependencies/generateTrackChronologyLinks.js b/src/content/dependencies/generateTrackChronologyLinks.js
index fd676942..e30dd9ba 100644
--- a/src/content/dependencies/generateTrackChronologyLinks.js
+++ b/src/content/dependencies/generateTrackChronologyLinks.js
@@ -1,4 +1,5 @@
 import {sortAlbumsTracksChronologically} from '#sort';
+import {accumulateSum} from '#sugar';
 
 import getChronologyRelations from '../util/getChronologyRelations.js';
 
@@ -86,33 +87,52 @@ export default {
   },
 
   generate(relations) {
-    function slotScopedRelations(scope) {
-      return scope.chronologyLinks.slots({
+    function slotScopedRelations(content) {
+      return content.chronologyLinks.slots({
         showOnly: true,
+        allowCollapsing: false,
 
         chronologyInfoSets: [
           {
             headingString: 'misc.chronology.heading.track',
-            contributions: scope.artistChronologyContributions,
+            contributions: content.artistChronologyContributions,
           },
           {
             headingString: 'misc.chronology.heading.coverArt',
-            contributions: scope.coverArtistChronologyContributions,
+            contributions: content.coverArtistChronologyContributions,
           },
         ],
       });
     }
 
-    return relations.scopeSwitcher.slots({
-      scopes: [
-        'wiki',
-        'album',
-      ],
+    const scopes = [
+      'wiki',
+      'album',
+    ];
 
-      contents: [
-        slotScopedRelations(relations.wiki),
-        slotScopedRelations(relations.album),
-      ],
+    const contents = [
+      relations.wiki,
+      relations.album,
+    ];
+
+    const totalContributionCount =
+      accumulateSum(
+        contents.flatMap(content => [
+          content.artistChronologyContributions,
+          content.coverArtistChronologyContributions,
+        ]),
+        contributions => contributions.length);
+
+    relations.scopeSwitcher.setSlots({
+      scopes,
+
+      open:
+        totalContributionCount <= 5,
+
+      contents:
+        contents.map(content => slotScopedRelations(content))
     });
+
+    return relations.scopeSwitcher;
   },
 };