« get me outta code hell

contracts: initial commit - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/contracts/adjacentAlbumsInGroup.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-05-02 14:58:27 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-05-02 14:58:54 -0300
commit4280c6240b88dadc8e5ea187b78c10aca9dfc163 (patch)
tree93ea9f2986fc378e7054c99f7e59c536cc2d5e20 /src/content/contracts/adjacentAlbumsInGroup.js
parentbf6bff764880f96597f915bd9a59abfaaf310db1 (diff)
contracts: initial commit
All draft stuff here for now, but this is *relatively* un-naive
as it's based on a lot of recent research and discussion.
But none of this code is evaluated yet!!
Diffstat (limited to 'src/content/contracts/adjacentAlbumsInGroup.js')
-rw-r--r--src/content/contracts/adjacentAlbumsInGroup.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/content/contracts/adjacentAlbumsInGroup.js b/src/content/contracts/adjacentAlbumsInGroup.js
new file mode 100644
index 00000000..e982fa5b
--- /dev/null
+++ b/src/content/contracts/adjacentAlbumsInGroup.js
@@ -0,0 +1,17 @@
+export default {
+  hook(contract, [album, group]) {
+    contract.provide({
+      group,
+      album,
+      albums: contract.selectProperty(group, 'albums'),
+    });
+  },
+
+  compute({group, album, albums}) {
+    const datedAlbums = albums.filter(album => album.date);
+    const index = datedAlbums.indexOf(album);
+    const previousAlbum = (index > 0) && datedAlbums[index - 1];
+    const nextAlbum = (index < datedAlbums.length - 1) && datedAlbums[index + 1];
+    return {previousAlbum, nextAlbum};
+  },
+};