« 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/generateContributionTooltipChronologySection.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/generateContributionTooltipChronologySection.js')
-rw-r--r--src/content/dependencies/generateContributionTooltipChronologySection.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/content/dependencies/generateContributionTooltipChronologySection.js b/src/content/dependencies/generateContributionTooltipChronologySection.js
new file mode 100644
index 00000000..85b19be9
--- /dev/null
+++ b/src/content/dependencies/generateContributionTooltipChronologySection.js
@@ -0,0 +1,51 @@
+export default {
+  contentDependencies: ['linkAnythingMan'],
+  extraDependencies: ['html', 'language'],
+
+  query(contribution) {
+    let previous = contribution;
+    while (previous && previous.thing === contribution.thing) {
+      previous = previous.previousBySameArtist;
+    }
+
+    let next = contribution;
+    while (next && next.thing === contribution.thing) {
+      next = next.nextBySameArtist;
+    }
+
+    return {previous, next};
+  },
+
+  relations: (relation, query, _contribution) => ({
+    previousLink:
+      (query.previous
+        ? relation('linkAnythingMan', query.previous.thing)
+        : null),
+
+    nextLink:
+      (query.next
+        ? relation('linkAnythingMan', query.next.thing)
+        : null),
+  }),
+
+  generate: (relations, {html, language}) =>
+    language.encapsulate('misc.artistLink.chronology', capsule => [
+      html.tag('span', {class: 'chronology-link'},
+        {[html.onlyIfContent]: true},
+
+        language.$(capsule, 'previous', {
+          [language.onlyIfOptions]: ['thing'],
+
+          thing: relations.previousLink,
+        })),
+
+      html.tag('span', {class: 'chronology-link'},
+        {[html.onlyIfContent]: true},
+
+        language.$(capsule, 'next', {
+          [language.onlyIfOptions]: ['thing'],
+
+          thing: relations.nextLink,
+        })),
+    ]),
+};