« get me outta code hell

content, data: Track.nameDetailWithinAlbum, directory magic, etc - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/things/Track.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2026-05-25 07:09:39 -0300
committer(quasar) nebula <qznebula@protonmail.com>2026-05-25 07:09:39 -0300
commitd783d3bf1eb1cd501d28dff58b258708a70d7e3c (patch)
treee8896add7353110093509a4c1ceedd64f535a78d /src/data/things/Track.js
parent44b1b14624ff3c87ae14d00b7e9f2ca34c5d63d3 (diff)
content, data: Track.nameDetailWithinAlbum, directory magic, etc
Diffstat (limited to 'src/data/things/Track.js')
-rw-r--r--src/data/things/Track.js154
1 files changed, 136 insertions, 18 deletions
diff --git a/src/data/things/Track.js b/src/data/things/Track.js
index 473de163..19d111e9 100644
--- a/src/data/things/Track.js
+++ b/src/data/things/Track.js
@@ -7,7 +7,7 @@ import find, {keyRefRegex} from '#find';
 import {onlyItem} from '#sugar';
 import {sortByDate, sortFlashesChronologically} from '#sort';
 import Thing from '#thing';
-import {compareKebabCase} from '#wiki-data';
+import {compareKebabCase, getKebabCase} from '#wiki-data';
 
 import {
   anyOf,
@@ -19,6 +19,7 @@ import {
   isDate,
   isExcludingURLsReason,
   isFileExtension,
+  isString,
   validateReference,
 } from '#validators';
 
@@ -153,13 +154,11 @@ export class Track extends Thing {
       exposeConstant(V('normal')),
     ],
 
-    nameDetail: simpleString(),
-
     directory: directory({
       suffix: 'directorySuffix',
     }),
 
-    suffixDirectoryFromAlbum: [
+    suffixDirectory: [
       exposeUpdateValueOrContinue({
         validate: input.value(isBoolean),
       }),
@@ -580,6 +579,16 @@ export class Track extends Thing {
 
     // > Update only
 
+    nameDetail: {
+      flags: {update: true},
+      update: {
+        validate:
+          anyOf(
+            is('album'),
+            isString),
+      },
+    },
+
     find: soupyFind(),
     reverse: soupyReverse(),
 
@@ -593,16 +602,101 @@ export class Track extends Thing {
 
     isTrack: exposeConstant(V(true)),
 
+    nameForReferencingAcrossWiki: [
+      // When referencing without any particular context,
+      // all referenceByDirectory values except for 'normally'
+      // count against referencing by name.
+      {
+        dependencies: ['referenceByDirectory'],
+        compute: (continuation, {referenceByDirectory}) =>
+          (referenceByDirectory !== 'normally'
+            ? continuation.exit(null)
+            : continuation()),
+      },
+
+      {
+        dependencies: ['name', 'nameDetailAcrossWiki'],
+        compute: (continuation, {name, nameDetailAcrossWiki}) =>
+          (nameDetailAcrossWiki
+            ? continuation.exit(`${name} (${nameDetailAcrossWiki})`)
+            : continuation()),
+      },
+
+      exposeDependency('name'),
+    ],
+
     commentatorArtists: commentatorArtists(),
 
     directorySuffix: [
-      exitWithoutDependency('suffixDirectoryFromAlbum', {
-        value: input.value(null),
-        mode: input.value('falsy'),
-      }),
-
       withPropertyFromObject('trackSection', V('directorySuffix')),
-      exposeDependency('#trackSection.directorySuffix'),
+
+      {
+        dependencies: [
+          '_suffixDirectory',
+           'suffixDirectory',
+          '#trackSection.directorySuffix',
+        ],
+
+        compute(continuation, {
+          ['_suffixDirectory']: suffixDirectoryUpdateValue,
+          [ 'suffixDirectory']: suffixDirectoryComputedValue,
+          ['#trackSection.directorySuffix']: directorySuffixFromAlbum,
+        }) {
+          // If directly set to true or inheriting true...
+          if (suffixDirectoryComputedValue === true) {
+            return directorySuffixFromAlbum;
+          }
+
+          // If directly set to false...
+          if (suffixDirectoryUpdateValue === false) {
+            return null;
+          }
+
+          // If inheriting false or defaulting to false...
+          return continuation();
+        },
+      },
+
+      // Don't follow any "automatic" directory suffix logic if the track's
+      // entire directory is set outright.
+      {
+        dependencies: ['_directory'],
+        compute(continuation, {
+          ['_directory']: directoryUpdateValue,
+        }) {
+          if (directoryUpdateValue) {
+            return null;
+          }
+
+          return continuation();
+        },
+      },
+
+      {
+        dependencies: [
+          '_nameDetail',
+           'nameDetailAcrossWiki',
+          '#trackSection.directorySuffix',
+        ],
+
+        compute(continuation, {
+          ['_nameDetail']: nameDetail,
+          [ 'nameDetailAcrossWiki']: nameDetailAcrossWiki,
+          ['#trackSection.directorySuffix']: directorySuffixFromAlbum,
+        }) {
+          if (nameDetail === 'album') {
+            return directorySuffixFromAlbum;
+          }
+
+          if (nameDetailAcrossWiki) {
+            return getKebabCase(nameDetailAcrossWiki);
+          }
+
+          return continuation();
+        },
+      },
+
+      exposeConstant(V(null)),
     ],
 
     date: [
@@ -639,6 +733,33 @@ export class Track extends Thing {
       },
     ],
 
+    nameDetailWithinAlbum: [
+      {
+        dependencies: ['_nameDetail'],
+        compute: ({
+          ['_nameDetail']: nameDetail,
+        }) =>
+          (nameDetail === 'album'
+            ? null
+            : nameDetail),
+      },
+    ],
+
+    nameDetailAcrossWiki: [
+      withPropertyFromObject('album', V('name')),
+
+      {
+        dependencies: ['_nameDetail', '#album.name'],
+        compute: ({
+          ['_nameDetail']: nameDetail,
+          ['#album.name']: albumName,
+        }) =>
+          (nameDetail === 'album'
+            ? albumName
+            : nameDetail),
+      },
+    ],
+
     // Whether or not the track has "unique" cover artwork - a cover which is
     // specifically associated with this track in particular, rather than with
     // the track's album as a whole. This is typically used to select between
@@ -979,7 +1100,7 @@ export class Track extends Thing {
       'Name Detail': {property: 'nameDetail'},
 
       'Directory': {property: 'directory'},
-      'Suffix Directory': {property: 'suffixDirectoryFromAlbum'},
+      'Suffix Directory': {property: 'suffixDirectory'},
 
       'Reference By Directory': {property: 'referenceByDirectory'},
 
@@ -1205,11 +1326,9 @@ export class Track extends Thing {
 
       bindTo: 'trackData',
 
-      // When referencing without any particular context, all values
-      // except for 'normally' count against referencing by name.
       getMatchableNames: track =>
-        (track.referenceByDirectory === 'normally'
-          ? [track.name]
+        (track.nameForReferencingAcrossWiki
+          ? [track.nameForReferencingAcrossWiki]
           : []),
     },
 
@@ -1220,10 +1339,9 @@ export class Track extends Thing {
       include: track =>
         !CacheableObject.getUpdateValue(track, 'mainRelease'),
 
-      // This is an acontextual reference.
       getMatchableNames: track =>
-        (track.referenceByDirectory === 'normally'
-          ? [track.name]
+        (track.nameForReferencingAcrossWiki
+          ? [track.nameForReferencingAcrossWiki]
           : []),
     },