« get me outta code hell

getChronologyRelations.js « util « content « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/util/getChronologyRelations.js
blob: 4b7d9ce59d0ea24a3108c32efdd56f0cc1f994e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
export default function getChronologyRelations(thing, {
  contributions,
  linkArtist,
  linkThing,
  getThings,
}) {
  return contributions.map(({who}) => {
    const things = Array.from(new Set(getThings(who)));
    const index = things.indexOf(thing);
    const previous = things[index - 1];
    const next = things[index + 1];
    return {
      index: index + 1,
      artistLink: linkArtist(who),
      previousLink: previous ? linkThing(previous) : null,
      nextLink: next ? linkThing(next) : null,
    };
  });
}