« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/content/dependencies/generateMusicVideo.js23
-rw-r--r--src/data/things/MusicVideo.js38
2 files changed, 33 insertions, 28 deletions
diff --git a/src/content/dependencies/generateMusicVideo.js b/src/content/dependencies/generateMusicVideo.js
index a481cb16..b62c0224 100644
--- a/src/content/dependencies/generateMusicVideo.js
+++ b/src/content/dependencies/generateMusicVideo.js
@@ -18,12 +18,12 @@ export default {
   }),
 
   data: (musicVideo, _thing) => ({
+    title:
+      musicVideo.title,
+
     label:
       musicVideo.label,
 
-    labelStyle:
-      musicVideo.labelStyle,
-
     url:
       musicVideo.url,
   }),
@@ -32,21 +32,18 @@ export default {
     language.encapsulate('misc.musicVideo', capsule =>
       html.tag('div', {class: 'music-video'}, [
         html.tag('p', {class: 'music-video-label'},
-          data.labelStyle !== 'label' &&
-            {class: data.labelStyle + '-style'},
+          data.title &&
+            {class: 'title-style'},
 
           language.encapsulate(capsule, 'label', workingCapsule => {
             const workingOptions = {};
 
-            if (data.label) {
+            if (data.title) {
+              workingCapsule += '.customLabel.title';
+              workingOptions.title = data.title;
+            } else if (data.label) {
               workingCapsule += '.customLabel';
-
-              if (data.labelStyle === 'title') {
-                workingCapsule += '.title';
-                workingOptions.title = data.label;
-              } else {
-                workingOptions.label = data.label;
-              }
+              workingOptions.label = data.label;
             }
 
             return language.$(workingCapsule, workingOptions);
diff --git a/src/data/things/MusicVideo.js b/src/data/things/MusicVideo.js
index 5016b9c3..b3dd31e6 100644
--- a/src/data/things/MusicVideo.js
+++ b/src/data/things/MusicVideo.js
@@ -12,7 +12,8 @@ import {
   exposeConstant,
   exposeDependency,
   exposeUpdateValueOrContinue,
-  withResultOfAvailabilityCheck,
+  exposeWhetherDependencyAvailable,
+  exitWithoutDependency,
 } from '#composite/control-flow';
 
 import {
@@ -34,21 +35,31 @@ export class MusicVideo extends Thing {
 
     thing: thing(),
 
-    label: {
+    title: {
       flags: {update: true, expose: true},
       update: {validate: isStringNonEmpty},
-      expose: {transform: value => value ?? 'Music video'},
     },
 
-    labelStyle: {
-      flags: {update: true, expose: true},
-      update: {
-        validate:
-          is('label', 'title'),
+    label: [
+      exposeUpdateValueOrContinue({
+        validate: input.value(isStringNonEmpty),
+      }),
+
+      exitWithoutDependency('title', V('Music video')),
+      exposeConstant(V(null)),
+    ],
+
+    unqualifiedDirectory: [
+      {
+        dependencies: ['title', 'label'],
+        compute: (continuation, {title, label}) =>
+          continuation({
+            '#name': label ?? title,
+          }),
       },
-    },
 
-    unqualifiedDirectory: directory({name: 'label'}),
+      directory({name: '#name'}),
+    ],
 
     date: [
       exposeUpdateValueOrContinue({
@@ -82,16 +93,13 @@ export class MusicVideo extends Thing {
 
     isMusicVideo: exposeConstant(V(true)),
 
-    dateIsSpecified: [
-      withResultOfAvailabilityCheck('_date'),
-      exposeDependency('#availability'),
-    ],
+    dateIsSpecified: exposeWhetherDependencyAvailable('_date'),
   });
 
   static [Thing.yamlDocumentSpec] = {
     fields: {
+      'Title': {property: 'title'},
       'Label': {property: 'label'},
-      'Label Style': {property: 'labelStyle'},
       'Directory': {property: 'unqualifiedDirectory'},
       'Date': {property: 'date', transform: parseDate},
       'URL': {property: 'url'},