« get me outta code hell

generateArtistInfoPageFlashesChunkedList.js « dependencies « content « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js
blob: a0eba8ff3a6c37798204ec1f25951200359deac9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import {sortContributionsChronologically, sortFlashesChronologically}
  from '#sort';
import {chunkByConditions, stitchArrays} from '#sugar';

export default {
  contentDependencies: [
    'generateArtistInfoPageChunkedList',
    'generateArtistInfoPageFlashesChunk',
  ],

  query(artist) {
    const query = {};

    const allContributions = [
      ...artist.flashContributorContributions,
    ];

    sortContributionsChronologically(
      allContributions,
      sortFlashesChronologically);

    query.contribs =
      chunkByConditions(allContributions, [
        ({thing: flash1}, {thing: flash2}) =>
          flash1.act !== flash2.act,
      ]);

    query.flashActs =
      query.contribs
        .map(contribs => contribs[0].thing)
        .map(thing => thing.act);

    return query;
  },

  relations: (relation, query, _artist) => ({
    chunkedList:
      relation('generateArtistInfoPageChunkedList'),

    chunks:
      stitchArrays({
        flashAct: query.flashActs,
        contribs: query.contribs,
      }).map(({flashAct, contribs}) =>
          relation('generateArtistInfoPageFlashesChunk', flashAct, contribs)),
  }),

  generate: (relations) =>
    relations.chunkedList.slots({
      chunks: relations.chunks,
    }),
};