-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
SongLyrics.tsx
114 lines (105 loc) · 3.32 KB
/
SongLyrics.tsx
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
import SafeAnchor from '@Bootstrap/SafeAnchor';
import SongDetailsForApi from '@DataContracts/Song/SongDetailsForApi';
import EntryUrlMapper from '@Shared/EntryUrlMapper';
import functions from '@Shared/GlobalFunctions';
import SongDetailsStore from '@Stores/Song/SongDetailsStore';
import { useStoreWithUpdateResults } from '@vocadb/route-sphere';
import classNames from 'classnames';
import _ from 'lodash';
import { runInAction } from 'mobx';
import { observer } from 'mobx-react-lite';
import qs from 'qs';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { userLanguageCultures } from '../userLanguageCultures';
import { SongDetailsTabs } from './SongDetailsRoutes';
interface SongLyricsProps {
model: SongDetailsForApi;
songDetailsStore: SongDetailsStore;
}
const SongLyrics = observer(
({ model, songDetailsStore }: SongLyricsProps): React.ReactElement => {
const { t } = useTranslation([
'ViewRes.Song',
'VocaDb.Web.Resources.Domain.Globalization',
]);
useStoreWithUpdateResults(songDetailsStore.lyricsStore);
return (
<SongDetailsTabs
model={model}
songDetailsStore={songDetailsStore}
tab="lyrics"
>
<ul className="nav nav-pills">
{_.chain(model.lyrics)
.sortBy((l) => l.translationType)
.value()
.map((lyrics) => (
<li
className={classNames(
songDetailsStore.selectedLyricsId === lyrics.id && 'active',
)}
key={lyrics.id}
>
<SafeAnchor
href={`${EntryUrlMapper.details_song(
model.contract.song,
)}/lyrics?${qs.stringify({
albumId: model.browsedAlbumId,
lyricsId: lyrics.id,
})}`}
onClick={(e): void => {
e.preventDefault();
runInAction(() => {
songDetailsStore.selectedLyricsId = lyrics.id!;
});
}}
>
{lyrics.translationType === 'Romanized'
? 'Romanized' /* TODO: localize */
: lyrics.cultureCode
? userLanguageCultures[lyrics.cultureCode].nativeName
: t('ViewRes.Song:Details.LyricsLanguageOther')}
{lyrics.translationType === 'Original' &&
` (${t(
'VocaDb.Web.Resources.Domain.Globalization:TranslationTypeNames.Original',
)})`}
</SafeAnchor>
</li>
))}
</ul>
{songDetailsStore.selectedLyrics && (
<div>
{(songDetailsStore.selectedLyrics.source ||
songDetailsStore.selectedLyrics.url) && (
<p>
({t('ViewRes.Song:Details.LyricsFrom')}{' '}
{songDetailsStore.selectedLyrics.url ? (
<span>
<a
className="extLink"
href={songDetailsStore.selectedLyrics.url}
onClick={(e): void =>
functions.trackOutboundLink(e.nativeEvent)
}
>
{songDetailsStore.selectedLyrics.source ||
songDetailsStore.selectedLyrics.url}
</a>
</span>
) : (
<span>{songDetailsStore.selectedLyrics.source}</span>
)}
)
</p>
)}
<p className="song-lyrics">
{songDetailsStore.selectedLyrics.value}
</p>
</div>
)}
</SongDetailsTabs>
);
},
);
export default SongLyrics;