From cd2767972a0f10504b3a731d736a13f6e53139c0 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 7 Mar 2024 12:01:45 -0400 Subject: data: withCoverArtDate --- src/data/composite/wiki-data/index.js | 1 + src/data/composite/wiki-data/withCoverArtDate.js | 56 ++++++++++++++++++++++++ src/data/things/album.js | 18 +++++--- 3 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 src/data/composite/wiki-data/withCoverArtDate.js (limited to 'src') diff --git a/src/data/composite/wiki-data/index.js b/src/data/composite/wiki-data/index.js index 10922d72..b16ef761 100644 --- a/src/data/composite/wiki-data/index.js +++ b/src/data/composite/wiki-data/index.js @@ -8,6 +8,7 @@ export {default as exitWithoutContribs} from './exitWithoutContribs.js'; export {default as inputWikiData} from './inputWikiData.js'; export {default as withClonedThings} from './withClonedThings.js'; export {default as withContributionListSums} from './withContributionListSums.js'; +export {default as withCoverArtDate} from './withCoverArtDate.js'; export {default as withDirectory} from './withDirectory.js'; export {default as withDirectoryFromName} from './withDirectoryFromName.js'; export {default as withParsedCommentaryEntries} from './withParsedCommentaryEntries.js'; diff --git a/src/data/composite/wiki-data/withCoverArtDate.js b/src/data/composite/wiki-data/withCoverArtDate.js new file mode 100644 index 00000000..7c16ce0f --- /dev/null +++ b/src/data/composite/wiki-data/withCoverArtDate.js @@ -0,0 +1,56 @@ +// Gets the current thing's coverArtDate, or, if the 'fallback' option is set, +// the thing's date. This is always null if the thing doesn't actually have +// any coverArtistContribs. + +import {input, templateCompositeFrom} from '#composite'; + +import {raiseOutputWithoutDependency} from '#composite/control-flow'; + +import withResolvedContribs from './withResolvedContribs.js'; + +export default templateCompositeFrom({ + annotation: `withCoverArtDate`, + + inputs: { + fallback: input({ + type: 'boolean', + defaultValue: false, + }), + }, + + outputs: ['#coverArtDate'], + + steps: () => [ + withResolvedContribs({ + from: 'coverArtistContribs', + date: input.value(null), + }), + + raiseOutputWithoutDependency({ + dependency: '#resolvedContribs', + mode: input.value('empty'), + output: input.value({'#coverArtDate': null}), + }), + + { + dependencies: ['coverArtDate', input('fallback')], + compute: (continuation, { + ['coverArtDate']: coverArtDate, + [input('fallback')]: fallback, + }) => + (coverArtDate + ? continuation.raiseOutput({'#coverArtDate': coverArtDate}) + : fallback + ? continuation() + : continuation.raiseOutput({'#coverArtDate': null})), + }, + + { + dependencies: ['date'], + compute: (continuation, {date}) => + (date + ? continuation.raiseOutput({'#coverArtDate': date}) + : continuation.raiseOutput({'#coverArtDate': null})), + }, + ], +}); diff --git a/src/data/things/album.js b/src/data/things/album.js index d2942fc7..6b37bc96 100644 --- a/src/data/things/album.js +++ b/src/data/things/album.js @@ -18,8 +18,13 @@ import {parseAdditionalFiles, parseContributors, parseDate, parseDimensions} import {exitWithoutDependency, exposeDependency, exposeUpdateValueOrContinue} from '#composite/control-flow'; import {withPropertyFromObject} from '#composite/data'; -import {exitWithoutContribs, withDirectory, withResolvedReference} - from '#composite/wiki-data'; + +import { + exitWithoutContribs, + withDirectory, + withResolvedReference, + withCoverArtDate, +} from '#composite/wiki-data'; import { additionalFiles, @@ -73,13 +78,12 @@ export class Album extends Thing { dateAddedToWiki: simpleDate(), coverArtDate: [ - exitWithoutContribs({contribs: 'coverArtistContribs'}), - - exposeUpdateValueOrContinue({ - validate: input.value(isDate), + // TODO: Why does this fall back, but Track.coverArtDate doesn't? + withCoverArtDate({ + fallback: input.value(true), }), - exposeDependency({dependency: 'date'}), + exposeDependency({dependency: '#coverArtDate'}), ], coverArtFileExtension: [ -- cgit 1.3.0-6-gf8a5