« get me outta code hell

data: withCoverArtDate - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/composite/wiki-data
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-03-07 12:01:45 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-06-18 22:56:03 -0300
commit588868e9b0f459a25aa0ade2c4a1a9e2701f729b (patch)
treea04bcaa25cc11ed7fb8beeb2e9a37b4c7977728a /src/data/composite/wiki-data
parent385721c1f2c37581dfa8473259ca4c98f7d9921d (diff)
data: withCoverArtDate
Diffstat (limited to 'src/data/composite/wiki-data')
-rw-r--r--src/data/composite/wiki-data/index.js1
-rw-r--r--src/data/composite/wiki-data/withCoverArtDate.js56
2 files changed, 57 insertions, 0 deletions
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})),
+    },
+  ],
+});