From 215aa2577d9d2e0812a8c42c90bd1d7ba83d2028 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 22 Dec 2022 22:33:24 -0400 Subject: many homepage carousel shenanigans --- src/data/things/homepage-layout.js | 14 ++++++++++++++ src/data/things/validators.js | 10 ++++++++++ src/data/yaml.js | 1 + 3 files changed, 25 insertions(+) (limited to 'src/data') 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) { diff --git a/src/data/yaml.js b/src/data/yaml.js index ae160d59..f967cee3 100644 --- a/src/data/yaml.js +++ b/src/data/yaml.js @@ -421,6 +421,7 @@ export function makeProcessHomepageLayoutRowDocument(rowClass, spec) { export const homepageLayoutRowTypeProcessMapping = { albums: makeProcessHomepageLayoutRowDocument(T.HomepageLayoutAlbumsRow, { propertyFieldMapping: { + displayStyle: 'Display Style', sourceGroupByRef: 'Group', countAlbumsFromGroup: 'Count', sourceAlbumsByRef: 'Albums', -- cgit 1.3.0-6-gf8a5