diff options
Diffstat (limited to 'src/content/contracts')
-rw-r--r-- | src/content/contracts/adjacentAlbumsInGroup.js | 17 |
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}; + }, +}; |