« get me outta code hell

data: soupy reverse - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/things/group.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2025-01-11 20:49:26 -0400
committer(quasar) nebula <qznebula@protonmail.com>2025-01-11 20:49:26 -0400
commit77fc589466fc0c04326231638c5ec6026e7948d4 (patch)
treedbc019e4f72851bd3fa8fd5195d87fe6f6177f7c /src/data/things/group.js
parent3bb0a89e80fddb985cc1fc4775e58b0d4a7445dc (diff)
data: soupy reverse
Diffstat (limited to 'src/data/things/group.js')
-rw-r--r--src/data/things/group.js58
1 files changed, 38 insertions, 20 deletions
diff --git a/src/data/things/group.js b/src/data/things/group.js
index 8bc71931..ed3c59bb 100644
--- a/src/data/things/group.js
+++ b/src/data/things/group.js
@@ -52,17 +52,7 @@ export class Group extends Thing {
     // Update only
 
     find: soupyFind(),
-
-    // used for albums (reverse)
-    albumData: wikiData({
-      class: input.value(Album),
-    }),
-
-    // used for category (reverse)
-    // used for color (reverse)
-    groupCategoryData: wikiData({
-      class: input.value(GroupCategory),
-    }),
+    reverse: soupyFind(),
 
     // Expose only
 
@@ -82,9 +72,9 @@ export class Group extends Thing {
       flags: {expose: true},
 
       expose: {
-        dependencies: ['this', 'albumData'],
-        compute: ({this: group, albumData}) =>
-          albumData?.filter((album) => album.groups.includes(group)) ?? [],
+        dependencies: ['this', 'reverse'],
+        compute: ({this: group, reverse}) =>
+          reverse.albumsWhoseGroupsInclude(group),
       },
     },
 
@@ -92,9 +82,9 @@ export class Group extends Thing {
       flags: {expose: true},
 
       expose: {
-        dependencies: ['this', 'groupCategoryData'],
-        compute: ({this: group, groupCategoryData}) =>
-          groupCategoryData.find((category) => category.groups.includes(group))
+        dependencies: ['this', 'reverse'],
+        compute: ({this: group, reverse}) =>
+          reverse.groupCategoriesWhichInclude(group, {unique: true})
             ?.color,
       },
     },
@@ -103,9 +93,9 @@ export class Group extends Thing {
       flags: {expose: true},
 
       expose: {
-        dependencies: ['this', 'groupCategoryData'],
-        compute: ({this: group, groupCategoryData}) =>
-          groupCategoryData.find((category) => category.groups.includes(group)) ??
+        dependencies: ['this', 'reverse'],
+        compute: ({this: group, reverse}) =>
+          reverse.groupCategoriesWhichInclude(group, {unique: true}) ??
           null,
       },
     },
@@ -118,6 +108,25 @@ export class Group extends Thing {
     },
   };
 
+  static [Thing.reverseSpecs] = {
+    groupsCloselyLinkedTo: {
+      bindTo: 'groupData',
+
+      referencing: group =>
+        group.closelyLinkedArtists
+          .map(({artist, ...referenceDetails}) => ({
+            group,
+            artist,
+            referenceDetails,
+          })),
+
+      referenced: ({artist}) => [artist],
+
+      tidy: ({group, referenceDetails}) =>
+        ({group, ...referenceDetails}),
+    },
+  };
+
   static [Thing.yamlDocumentSpec] = {
     fields: {
       'Group': {property: 'name'},
@@ -217,6 +226,15 @@ export class GroupCategory extends Thing {
     find: soupyFind(),
   });
 
+  static [Thing.reverseSpecs] = {
+    groupCategoriesWhichInclude: {
+      bindTo: 'groupCategoryData',
+
+      referencing: groupCategory => [groupCategory],
+      referenced: groupCategory => groupCategory.groups,
+    },
+  };
+
   static [Thing.yamlDocumentSpec] = {
     fields: {
       'Category': {property: 'name'},