« get me outta code hell

generateGroupGalleryPage.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/generateGroupGalleryPage.js
blob: 535a2bc9859113693f0da483fe7908eb288e2898 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import {sortChronologically} from '#sort';
import {filterItemsForCarousel, getTotalDuration} from '#wiki-data';

export default {
  contentDependencies: [
    'generateCoverCarousel',
    'generateGroupGalleryPageAlbumsByDateView',
    'generateGroupGalleryPageAlbumsBySeriesView',
    'generateGroupNavLinks',
    'generateGroupSecondaryNav',
    'generateIntrapageDotSwitcher',
    'generatePageLayout',
    'generateQuickDescription',
    'image',
    'linkAlbum',
    'linkListing',
  ],

  extraDependencies: ['html', 'language', 'wikiData'],

  sprawl: ({wikiInfo}) =>
    ({enableGroupUI: wikiInfo.enableGroupUI}),

  query(_sprawl, group) {
    const query = {};

    query.allAlbums =
      sortChronologically(group.albums.slice(), {latestFirst: true});

    query.allTracks =
      query.allAlbums.flatMap((album) => album.tracks);

    query.carouselAlbums =
      filterItemsForCarousel(group.featuredAlbums);

    return query;
  },

  relations: (relation, query, sprawl, group) => ({
    layout:
      relation('generatePageLayout'),

    navLinks:
      relation('generateGroupNavLinks', group),

    secondaryNav:
      (sprawl.enableGroupUI
        ? relation('generateGroupSecondaryNav', group)
        : null),

    coverCarousel:
      relation('generateCoverCarousel'),

    carouselLinks:
      query.carouselAlbums
        .map(album => relation('linkAlbum', album)),

    carouselImages:
      query.carouselAlbums
        .map(album => relation('image', album.coverArtworks[0])),

    quickDescription:
      relation('generateQuickDescription', group),

    albumViewSwitcher:
      relation('generateIntrapageDotSwitcher'),

    albumsBySeriesView:
      relation('generateGroupGalleryPageAlbumsBySeriesView', group),

    albumsByDateView:
      relation('generateGroupGalleryPageAlbumsByDateView', group),
  }),

  data: (query, _sprawl, group) => ({
    name:
      group.name,

    color:
      group.color,

    numAlbums:
      query.allAlbums.length,

    numTracks:
      query.allTracks.length,

    totalDuration:
      getTotalDuration(query.allTracks, {mainReleasesOnly: true}),
  }),

  generate: (data, relations, {html, language}) =>
    language.encapsulate('groupGalleryPage', pageCapsule =>
      relations.layout.slots({
        title: language.$(pageCapsule, 'title', {group: data.name}),
        headingMode: 'static',

        color: data.color,

        mainClasses: ['top-index'],
        mainContent: [
          relations.coverCarousel.slots({
            links: relations.carouselLinks,
            images: relations.carouselImages,
          }),

          relations.quickDescription,

          html.tag('p', {class: 'quick-info'},
            language.$(pageCapsule, 'infoLine', {
              tracks:
                html.tag('b',
                  language.countTracks(data.numTracks, {
                    unit: true,
                  })),

              albums:
                html.tag('b',
                  language.countAlbums(data.numAlbums, {
                    unit: true,
                  })),

              time:
                html.tag('b',
                  language.formatDuration(data.totalDuration, {
                    unit: true,
                  })),
            })),

          ([
            !html.isBlank(relations.albumsBySeriesView),
            !html.isBlank(relations.albumsByDateView)
          ]).filter(Boolean).length > 1 &&

            language.encapsulate(pageCapsule, 'albumViewSwitcher', capsule =>
              html.tag('p', {class: 'gallery-view-switcher'},
                {[html.onlyIfContent]: true},
                {[html.joinChildren]: html.tag('br')},

                [
                  language.$(capsule),

                  relations.albumViewSwitcher.slots({
                    initialOptionIndex: 0,

                    titles: [
                      !html.isBlank(relations.albumsBySeriesView) &&
                        language.$(capsule, 'bySeries'),

                      !html.isBlank(relations.albumsByDateView) &&
                        language.$(capsule, 'byDate'),
                    ].filter(Boolean),

                    targetIDs: [
                      !html.isBlank(relations.albumsBySeriesView) &&
                        'group-album-gallery-by-series',

                      !html.isBlank(relations.albumsByDateView) &&
                        'group-album-gallery-by-date',
                    ].filter(Boolean),
                  }),
                ])),

          /*
          data.trackGridLabels.some(value => value !== null) &&
            html.tag('p', {class: 'gallery-set-switcher'},
              language.encapsulate(pageCapsule, 'setSwitcher', switcherCapsule =>
                language.$(switcherCapsule, {
                  sets:
                    relations.setSwitcher.slots({
                      initialOptionIndex: 0,

                      titles:
                        data.trackGridLabels.map(label =>
                          label ??
                          language.$(switcherCapsule, 'unlabeledSet')),

                      targetIDs:
                        data.trackGridIDs,
                    }),
                }))),
          */

          relations.albumsBySeriesView,

          relations.albumsByDateView.slots({
            attributes: [
              !html.isBlank(relations.albumsBySeriesView) &&
                {style: 'display: none'},
            ],
          }),
        ],

        navLinkStyle: 'hierarchical',
        navLinks:
          relations.navLinks
            .slot('currentExtra', 'gallery')
            .content,

        secondaryNav: relations.secondaryNav,
      })),
};