« get me outta code hell

adjacentAlbumsInGroup.js « contracts « content « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/contracts/adjacentAlbumsInGroup.js
blob: e982fa5b939c6ee0d5a8f6344d56334703c04a8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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};
  },
};