« get me outta code hell

generateTrackInfoPageOtherReleasesLine.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/generateTrackInfoPageOtherReleasesLine.js
blob: e2dffea666af8826196e6c35bbb52ec59573bb10 (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
import {onlyItem, stitchArrays} from '#sugar';

export default {
  query(track) {
    const query = {};

    query.singleSingle =
      onlyItem(
        track.otherReleases.filter(track => track.album.style === 'single'));

    query.regularReleases =
      (query.singleSingle
        ? track.otherReleases.filter(track => track !== query.singleSingle)
        : track.otherReleases);

    return query;
  },

  relations: (relation, query, track) => ({
    textWithTooltip:
      relation('generateTextWithTooltip'),

    singleLink:
      (query.singleSingle
        ? relation('linkTrack', query.singleSingle)
        : null),

    singleTooltip:
      (query.singleSingle
        ? relation('generateTrackInfoPageOtherReleaseTooltip',
            query.singleSingle, track)
        : null),

    trackLinks:
      query.regularReleases
        .map(track => relation('linkTrack', track)),

    trackTooltips:
      query.regularReleases
        .map(otherTrack =>
          relation('generateTrackInfoPageOtherReleaseTooltip',
            otherTrack, track)),
  }),

  data: (query, _track) => ({
    albumNames:
      query.regularReleases
        .map(track => track.album.name),

    albumColors:
      query.regularReleases
        .map(track => track.album.color),
  }),

  generate: (data, relations, {html, language}) =>
    language.encapsulate('releaseInfo.alsoReleased', capsule =>
      language.encapsulate(capsule, workingCapsule => {
        const workingOptions = {};

        let any = false;

        const albumList =
          language.formatConjunctionList(
            stitchArrays({
              trackLink: relations.trackLinks,
              trackTooltip: relations.trackTooltips,
              albumName: data.albumNames,
              albumColor: data.albumColors,
            }).map(({
                trackLink,
                trackTooltip,
                albumName,
                albumColor,
              }) =>
                relations.textWithTooltip.clone().slots({
                  customInteractionCue: true,

                  text:
                    trackLink.slots({
                      attributes: {class: 'text-with-tooltip-interaction-cue'},
                      content: language.sanitize(albumName),
                      color: albumColor,
                    }),

                  tooltip:
                    trackTooltip,
                })));

        if (!html.isBlank(albumList)) {
          any = true;
          workingCapsule += '.onAlbums';
          workingOptions.albums = albumList;
        }

        if (relations.singleLink) {
          any = true;
          workingCapsule += '.asSingle';
          workingOptions.single =
            relations.textWithTooltip.clone().slots({
              customInteractionCue: true,

              text:
                relations.singleLink.slots({
                  attributes: {class: 'text-with-tooltip-interaction-cue'},
                  content: language.$(capsule, 'single'),
                }),

              tooltip:
                relations.singleTooltip,
            });
        }

        if (any) {
          return language.$(workingCapsule, workingOptions);
        } else {
          return html.blank();
        }
      })),
};