« get me outta code hell

generateArtistInfoPageArtworksChunkedList.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/generateArtistInfoPageArtworksChunkedList.js
blob: caefb7a32c6d01e7c86a3e00f209bb679d4f75ba (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
53
54
55
56
57
58
import {sortAlbumsTracksChronologically, sortContributionsChronologically}
  from '#sort';
import {chunkByConditions, stitchArrays} from '#sugar';

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

  query(artist) {
    const query = {};

    const allContributions = [
      ...artist.albumCoverArtistContributions,
      ...artist.albumWallpaperArtistContributions,
      ...artist.albumBannerArtistContributions,
      ...artist.trackCoverArtistContributions,
    ];

    sortContributionsChronologically(
      allContributions,
      sortAlbumsTracksChronologically);

    query.contribs =
      chunkByConditions(allContributions, [
        ({date: date1}, {date: date2}) =>
          +date1 !== +date2,
        ({thing: thing1}, {thing: thing2}) =>
          (thing1.album ?? thing1) !==
          (thing2.album ?? thing2),
      ]);

    query.albums =
      query.contribs
        .map(contribs => contribs[0].thing)
        .map(thing => thing.album ?? thing);

    return query;
  },

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

    chunks:
      stitchArrays({
        album: query.albums,
        contribs: query.contribs,
      }).map(({album, contribs}) =>
          relation('generateArtistInfoPageArtworksChunk', album, contribs)),
  }),

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