« 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: 8b024147d39264cb4f8f48717d79194fa048e7a6 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
import {sortAlbumsTracksChronologically, sortContributionsChronologically}
  from '#sort';
import {chunkByConditions, stitchArrays} from '#sugar';

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

  query(artist, filterEditsForWiki) {
    const query = {};

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

    const filteredContributions =
      allContributions
        .filter(({annotation}) =>
          (filterEditsForWiki
            ? annotation?.startsWith(`edits for wiki`)
            : !annotation?.startsWith(`edits for wiki`)));

    sortContributionsChronologically(
      filteredContributions,
      sortAlbumsTracksChronologically);

    query.contribs =
      chunkByConditions(filteredContributions, [
        ({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, _filterEditsForWiki) => ({
    chunkedList:
      relation('generateArtistInfoPageChunkedList'),

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

  data: (_query, _artist, filterEditsForWiki) => ({
    filterEditsForWiki,
  }),

  generate: (data, relations) =>
    relations.chunkedList.slots({
      chunks:
        relations.chunks.map(chunk =>
          chunk.slot('filterEditsForWiki', data.filterEditsForWiki)),
    }),
};