« get me outta code hell

content: generateTrackChronologyLinks: handle details collapsing - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateTrackChronologyLinks.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-04-23 16:54:41 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-30 20:48:18 -0300
commitb1fc03df98d7618f5a5189089bd810f243e9aa8c (patch)
tree3a89079cc5c43107f88b98ceae2bf90eff90b658 /src/content/dependencies/generateTrackChronologyLinks.js
parent5b4f7bd906d658116b384122518c43a577141368 (diff)
content: generateTrackChronologyLinks: handle details collapsing
Diffstat (limited to 'src/content/dependencies/generateTrackChronologyLinks.js')
-rw-r--r--src/content/dependencies/generateTrackChronologyLinks.js46
1 files changed, 33 insertions, 13 deletions
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;
   },
 };