« 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
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
parent5b4f7bd906d658116b384122518c43a577141368 (diff)
content: generateTrackChronologyLinks: handle details collapsing
Diffstat (limited to 'src')
-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;
   },
 };