« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/things
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/things')
-rw-r--r--src/data/things/homepage-layout.js14
-rw-r--r--src/data/things/validators.js10
2 files changed, 24 insertions, 0 deletions
diff --git a/src/data/things/homepage-layout.js b/src/data/things/homepage-layout.js
index 5948ff46..32b8cf2a 100644
--- a/src/data/things/homepage-layout.js
+++ b/src/data/things/homepage-layout.js
@@ -65,6 +65,7 @@ export class HomepageLayoutAlbumsRow extends HomepageLayoutRow {
       isCountingNumber,
       isString,
       validateArrayItems,
+      validateFromConstants,
     },
   } = opts) => ({
     ...HomepageLayoutRow[Thing.getPropertyDescriptors](opts),
@@ -84,6 +85,19 @@ export class HomepageLayoutAlbumsRow extends HomepageLayoutRow {
       },
     },
 
+    displayStyle: {
+      flags: {update: true, expose: true},
+
+      update: {
+        validate: validateFromConstants('grid', 'montage'),
+      },
+
+      expose: {
+        transform: (displayStyle) =>
+          displayStyle ?? 'grid',
+      },
+    },
+
     sourceGroupByRef: Thing.common.singleReference(Group),
     sourceAlbumsByRef: Thing.common.referenceList(Album),
 
diff --git a/src/data/things/validators.js b/src/data/things/validators.js
index cc603d48..a0d473ba 100644
--- a/src/data/things/validators.js
+++ b/src/data/things/validators.js
@@ -162,6 +162,16 @@ export function validateInstanceOf(constructor) {
   return (object) => isInstance(object, constructor);
 }
 
+export function validateFromConstants(...values) {
+  return (value) => {
+    if (!values.includes(value)) {
+      throw new TypeError(`Expected one of ${values.join(', ')}`);
+    }
+
+    return true;
+  };
+}
+
 // Wiki data (primitives & non-primitives)
 
 export function isColor(color) {