« get me outta code hell

Merge branch 'shared-additional-names' into preview - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateTrackAdditionalNamesBox.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-12-03 17:50:39 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-12-03 17:50:39 -0400
commit2d054508f58147f5968a10f39c2f87ba62dd91f7 (patch)
tree2f808645119b9062a4e0ea1a3a9e8256f84af7e8 /src/content/dependencies/generateTrackAdditionalNamesBox.js
parent7ad62ef4a6908a550d5b48ae93877446088d4d82 (diff)
parentc336352a915245e28e08498de61808c96daa3dcf (diff)
Merge branch 'shared-additional-names' into preview
Diffstat (limited to 'src/content/dependencies/generateTrackAdditionalNamesBox.js')
-rw-r--r--src/content/dependencies/generateTrackAdditionalNamesBox.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/content/dependencies/generateTrackAdditionalNamesBox.js b/src/content/dependencies/generateTrackAdditionalNamesBox.js
new file mode 100644
index 00000000..bad04b74
--- /dev/null
+++ b/src/content/dependencies/generateTrackAdditionalNamesBox.js
@@ -0,0 +1,53 @@
+import {empty} from '#sugar';
+
+export default {
+  contentDependencies: ['generateAdditionalNamesBox'],
+  extraDependencies: ['html'],
+
+  query: (track) => {
+    const {
+      additionalNames: own,
+      sharedAdditionalNames: shared,
+      inferredAdditionalNames: inferred,
+    } = track;
+
+    if (empty(own) && empty(shared) && empty(inferred)) {
+      return {combinedList: []};
+    }
+
+    const firstFilter =
+      (empty(own)
+        ? new Set()
+        : new Set(own.map(({name}) => name)));
+
+    const sharedFiltered =
+      shared.filter(({name}) => !firstFilter.has(name))
+
+    const secondFilter =
+      new Set([
+        ...firstFilter,
+        ...sharedFiltered.map(({name}) => name),
+      ]);
+
+    const inferredFiltered =
+      inferred.filter(({name}) => !secondFilter.has(name));
+
+    return {
+      combinedList: [
+        ...own,
+        ...sharedFiltered,
+        ...inferredFiltered,
+      ],
+    };
+  },
+
+  relations: (relation, query) => ({
+    box:
+      (empty(query.combinedList)
+        ? null
+        : relation('generateAdditionalNamesBox', query.combinedList)),
+  }),
+
+  generate: (relations, {html}) =>
+    relations.box ?? html.blank(),
+};