« get me outta code hell

basic page writes - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2022-02-20 00:24:56 -0400
committer(quasar) nebula <qznebula@protonmail.com>2022-02-20 00:24:56 -0400
commit71de050864a42afcaeb409c11b9c792653cf2f1b (patch)
tree63e8b1d3d03db4f3504b9c3a65d57223c61b39e2 /src/data
parentf26ad2e27e9c7ca61b6ae5e9b3587786d911a2df (diff)
basic page writes
Diffstat (limited to 'src/data')
-rw-r--r--src/data/things.js74
-rw-r--r--src/data/validators.js7
2 files changed, 77 insertions, 4 deletions
diff --git a/src/data/things.js b/src/data/things.js
index 4f4c2908..90d09b9c 100644
--- a/src/data/things.js
+++ b/src/data/things.js
@@ -20,6 +20,7 @@ import {
     isNumber,
     isURL,
     isString,
+    isWholeNumber,
     oneOf,
     validateArrayItems,
     validateInstanceOf,
@@ -270,7 +271,7 @@ Thing.common = {
         expose: {
             dependencies: ['artistData', contribsByRefProperty],
             compute: ({ artistData, [contribsByRefProperty]: contribsByRef }) => (
-                (contribsByRef && artistData
+                ((contribsByRef && artistData)
                     ? (contribsByRef
                         .map(({ who: ref, what }) => ({
                             who: find.artist(ref, {wikiData: {artistData}}),
@@ -329,7 +330,10 @@ Thing.common = {
             dependencies: [wikiDataProperty],
 
             compute: ({ [wikiDataProperty]: wikiData, [Thing.instance]: thing }) => (
-                wikiData?.filter(t => t[referencerRefListProperty]?.includes(thing)))
+                (wikiData
+                    ? wikiData.filter(t => t[referencerRefListProperty]?.includes(thing))
+                    : [])
+            )
         }
     }),
 
@@ -466,7 +470,25 @@ TrackGroup.propertyDescriptors = {
     // Update & expose
 
     name: Thing.common.name('Unnamed Track Group'),
-    color: Thing.common.color(),
+
+    color: {
+        flags: {update: true, expose: true},
+
+        update: {validate: isColor},
+
+        expose: {
+            dependencies: ['album'],
+
+            transform(color, { album }) {
+                return color ?? album?.color ?? null;
+            }
+        }
+    },
+
+    startIndex: {
+        flags: {update: true, expose: true},
+        update: {validate: isWholeNumber}
+    },
 
     dateOriginallyReleased: Thing.common.simpleDate(),
 
@@ -476,6 +498,11 @@ TrackGroup.propertyDescriptors = {
 
     // Update only
 
+    album: {
+        flags: {update: true},
+        update: {validate: validateInstanceOf(Album)}
+    },
+
     trackData: Thing.common.wikiData(Track),
 
     // Expose only
@@ -544,6 +571,7 @@ Track.propertyDescriptors = {
     albumData: Thing.common.wikiData(Album),
     artistData: Thing.common.wikiData(Artist),
     artTagData: Thing.common.wikiData(ArtTag),
+    flashData: Thing.common.wikiData(Flash),
     trackData: Thing.common.wikiData(Track),
 
     // Expose only
@@ -565,12 +593,26 @@ Track.propertyDescriptors = {
             dependencies: ['albumData', 'dateFirstReleased'],
             compute: ({ albumData, dateFirstReleased, [Track.instance]: track }) => (
                 dateFirstReleased ??
-                Track.findAlbum(track)?.date ??
+                Track.findAlbum(track, albumData)?.date ??
                 null
             )
         }
     },
 
+    color: {
+        flags: {expose: true},
+
+        expose: {
+            dependencies: ['albumData', 'trackData'],
+
+            compute: ({ albumData, trackData, [Track.instance]: track }) => (
+                (Track.findAlbum(track, albumData)?.trackGroups
+                    .find(tg => tg.tracks.includes(track))?.color)
+                ?? null
+            )
+        }
+    },
+
     coverArtDate: {
         flags: {update: true, expose: true},
 
@@ -588,6 +630,30 @@ Track.propertyDescriptors = {
         }
     },
 
+    otherReleases: {
+        flags: {expose: true},
+
+        expose: {
+            dependencies: ['originalReleaseTrackByRef', 'trackData'],
+
+            compute: ({ originalReleaseTrackByRef: ref1, trackData, [Track.instance]: t1 }) => (
+                (ref1 && trackData
+                    ? [
+                        find.track(ref1, {wikiData: {trackData}}),
+                        ...trackData.filter(t2 => {
+                            const { originalReleaseTrackByRef: ref2 } = t2;
+                            return (
+                                t2 !== t1 &&
+                                ref2 &&
+                                (
+                                    find.track(ref2, {wikiData: {trackData}}) ===
+                                    find.track(ref1, {wikiData: {trackData}})))
+                        })]
+                    : [])
+            )
+        }
+    },
+
     // Previously known as: (track).artists
     artistContribs: Thing.common.dynamicInheritContribs('artistContribsByRef', 'artistContribsByRef', 'albumData', Track.findAlbum),
 
diff --git a/src/data/validators.js b/src/data/validators.js
index 83922229..ca10833e 100644
--- a/src/data/validators.js
+++ b/src/data/validators.js
@@ -81,6 +81,13 @@ export function isCountingNumber(number) {
     return true;
 }
 
+export function isWholeNumber(number) {
+    isInteger(number);
+    isPositiveOrZero(number);
+
+    return true;
+}
+
 export function isString(value) {
     return isType(value, 'string');
 }