« get me outta code hell

generateTrackInfoPageOtherReleaseTooltip.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/generateTrackInfoPageOtherReleaseTooltip.js
blob: 4c6bda1be031559feccc708d42f72d8cf77ce675 (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
import {compareKebabCase} from '#wiki-data';

export default {
  relations: (relation, otherTrack, _currentTrack) => ({
    tooltip:
      relation('generateTooltip'),

    colorStyle:
      relation('generateColorStyleAttribute', otherTrack.album.color),
  }),

  data: (otherTrack, currentTrack) => ({
    otherDate:
      otherTrack.date,

    currentDate:
      currentTrack.date,

    differentName:
      (compareKebabCase(otherTrack.name, currentTrack.name)
        ? null
        : otherTrack.name),

    onSingle:
      otherTrack.album.style === 'single',
  }),

  generate: (data, relations, {html, language}) =>
    language.encapsulate('releaseInfo.alsoReleased.tooltip', capsule =>
      relations.tooltip.slots({
        attributes: [
          {class: 'other-release-tooltip'},
          relations.colorStyle,
        ],

        contentAttributes: [
          {[html.joinChildren]:
            html.tag('span', {class: 'cute-break'})},
        ],

        content: [
          language.encapsulate(capsule, 'differentName', workingCapsule => {
            const workingOptions = {
              [language.onlyIfOptions]: ['name'],
              name: data.differentName,
            };

            if (data.onSingle) {
              workingCapsule += '.onSingle';
            }

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

          data.otherDate && data.currentDate &&
            html.tag('span', {class: 'when'},
              language.formatRelativeDate(data.otherDate, data.currentDate, {
                considerRoundingDays: true,
                approximate: true,
                absolute: false,
              })),
        ],
      })),
};