« get me outta code hell

generateGroupGalleryPageAlbumGridTab.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/generateGroupGalleryPageAlbumGridTab.js
blob: bc916b1b8c4cfc88a7eeee33230b4d368ebba11e (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
72
73
74
75
76
import {empty} from '#sugar';

export default {
  query(album, group) {
    if (album.groups.length > 1) {
      const currentCategory = group.category;

      const candidateGroups =
        album.groups
          .filter(group => !group.excludeFromOtherGroupAlbumSummaries);

      const categoriesToGroups =
        Map.groupBy(candidateGroups, group => group.category);

      for (const [category, groups] of categoriesToGroups) {
        if (category === currentCategory) {
          continue;
        }

        if (empty(groups)) {
          continue;
        }

        return {mode: 'groups', groups};
      }
    }

    if (!empty(album.artistContribs)) {
      if (album.artistContribs.length >= 2) {
        return {mode: 'artists'};
      };

      const onlyAlbumArtist = album.artistContribs[0].artist;
      const firstGroupArtist = group.closelyLinkedArtists[0]?.artist;

      if (!firstGroupArtist || onlyAlbumArtist !== firstGroupArtist) {
        return {mode: 'artists'};
      }
    }

    return {mode: null};
  },

  relations: (relation, query, album, _group) => ({
    artistCredit:
      (query.mode === 'artists'
        ? relation('generateArtistCredit', album.artistContribs, [])
        : null),
  }),

  data: (query, _album, _group) => ({
    mode: query.mode,

    groupNames:
      (query.mode === 'groups'
        ? query.groups.map(group => group.name)
        : null),
  }),

  generate: (data, relations, {language}) =>
    language.encapsulate('misc.coverGrid.tab', capsule =>
      (data.mode === 'groups'
        ? language.$(capsule, 'groups', {
            groups:
              language.formatUnitList(data.groupNames),
          })
     : data.mode === 'artists'
        ? relations.artistCredit.slots({
            normalStringKey:
              capsule + '.artists',

            normalFeaturingStringKey:
              capsule + '.artists.featuring',
          })
        : null)),
};