« 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: 92ab52ba95c61957e76567cd663b448866a99644 (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
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),
  }),

  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.$(capsule, 'differentName', {
            [language.onlyIfOptions]: ['name'],

            name: data.differentName,
          }),

          data.otherDate && data.currentDate &&
            language.formatRelativeDate(data.otherDate, data.currentDate, {
              considerRoundingDays: true,
              approximate: true,
              absolute: false,
            }),
        ],
      })),
};