« get me outta code hell

generateGroupInfoPageAlbumsSection.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/generateGroupInfoPageAlbumsSection.js
blob: 8899e98e0d3d4d0083580e3d64a0bc31ae7d712c (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
import {empty} from '#sugar';
import {stitchArrays} from '#sugar';

export default {
  contentDependencies: [
    'generateAbsoluteDatetimestamp',
    'generateColorStyleAttribute',
    'generateContentHeading',
    'linkAlbum',
    'linkGroupGallery',
    'linkGroup',
  ],

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

  query(group) {
    const albums =
      group.albums;

    const albumGroups =
      albums
        .map(album => album.groups);

    const albumOtherCategory =
      albumGroups
        .map(groups => groups
          .map(group => group.category)
          .find(category => category !== group.category));

    const albumOtherGroups =
      stitchArrays({
        groups: albumGroups,
        category: albumOtherCategory,
      }).map(({groups, category}) =>
          groups
            .filter(group => group.category === category));

    return {albums, albumOtherGroups};
  },

  relations: (relation, query, group) => ({
    contentHeading:
      relation('generateContentHeading'),

    galleryLink:
      relation('linkGroupGallery', group),

    albumColorStyles:
      query.albums
        .map(album => relation('generateColorStyleAttribute', album.color)),

    albumLinks:
      query.albums
        .map(album => relation('linkAlbum', album)),

    otherGroupLinks:
      query.albumOtherGroups
        .map(groups => groups
          .map(group => relation('linkGroup', group))),

    datetimestamps:
      group.albums.map(album =>
        (album.date
          ? relation('generateAbsoluteDatetimestamp', album.date)
          : null)),
  }),

  generate: (relations, {html, language}) =>
    language.encapsulate('groupInfoPage', pageCapsule =>
      language.encapsulate(pageCapsule, 'albumList', listCapsule =>
        html.tags([
          relations.contentHeading
            .slots({
              tag: 'h2',
              title: language.$(listCapsule, 'title'),
            }),

          html.tag('p',
            {[html.onlyIfSiblings]: true},

            language.encapsulate(pageCapsule, 'viewAlbumGallery', capsule =>
              language.$(capsule, {
                link:
                  relations.galleryLink
                    .slot('content', language.$(capsule, 'link')),
              }))),

          html.tag('ul',
            {[html.onlyIfContent]: true},

            stitchArrays({
              albumLink: relations.albumLinks,
              otherGroupLinks: relations.otherGroupLinks,
              datetimestamp: relations.datetimestamps,
              albumColorStyle: relations.albumColorStyles,
            }).map(({
                albumLink,
                otherGroupLinks,
                datetimestamp,
                albumColorStyle,
              }) =>
                html.tag('li',
                  albumColorStyle,

                  language.encapsulate(listCapsule, 'item', itemCapsule =>
                    language.encapsulate(itemCapsule, workingCapsule => {
                      const workingOptions = {};

                      workingOptions.album =
                        albumLink.slot('color', false);

                      if (datetimestamp) {
                        workingCapsule += '.withYear';
                        workingOptions.yearAccent =
                          language.$(itemCapsule, 'yearAccent', {
                            year:
                              datetimestamp.slots({style: 'year', tooltip: true}),
                          });
                      }

                      if (!empty(otherGroupLinks)) {
                        workingCapsule += '.withOtherGroup';
                        workingOptions.otherGroupAccent =
                          html.tag('span', {class: 'other-group-accent'},
                            language.$(itemCapsule, 'otherGroupAccent', {
                              groups:
                                language.formatConjunctionList(
                                  otherGroupLinks.map(groupLink =>
                                    groupLink.slot('color', false))),
                            }));
                      }

                      return language.$(workingCapsule, workingOptions);
                    }))))),
        ]))),
};