-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImmersiveLyricsColumn.tsx
More file actions
278 lines (272 loc) Β· 10.6 KB
/
Copy pathImmersiveLyricsColumn.tsx
File metadata and controls
278 lines (272 loc) Β· 10.6 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
import { Fragment, useEffect, useRef } from "react";
import { useTranslation } from "react-i18next";
import { Music2, AlertCircle, Upload, RefreshCcw } from "lucide-react";
import { Artwork } from "../common/Artwork";
import type { Track } from "../../lib/tauri/track";
import type { LyricsLine, LyricsPayload } from "../../lib/tauri/lyrics";
import { useFullscreenLyricsCentering } from "../../hooks/useFullscreenLyricsCentering";
interface ImmersiveLyricsColumnProps {
track: Track;
payload: LyricsPayload | null;
lrcLines: LyricsLine[];
isSynced: boolean;
activeIndex: number;
activeWordIndex: number;
isFetching: boolean;
error: string | null;
/** Radio: timestamp-stripped static text (overrides `payload.content`
* in the non-synced branch). `null` falls back to the raw content. */
staticText: string | null;
/** Live Web Radio session β hides the import / refetch CTA (no library
* row to attach lyrics to). */
isRadio: boolean;
onSeek: (line: LyricsLine) => void;
onImport: () => void;
onRefetch: () => void;
/** Header with cover + title (shown in the classic lyrics-only
* fullscreen; hidden in the dual-column layout where the now-playing
* column already carries the cover + big title). */
showHeader?: boolean;
/** When set, the header cover becomes a button (classic mode uses it to
* flip back to the now-playing fullscreen, like the old overlay). */
onCoverClick?: () => void;
}
/**
* Right column of the immersive view (issue #328): the synced karaoke
* lyrics scroller. Lifted from the old `FullscreenLyrics` body, but the
* fetch/parse/active-line state now arrives as props from the shared
* `useTrackLyrics` hook (owned by `ImmersiveView`) instead of being
* threaded from the side panel β so the merged view never double-fetches.
*
* Auto-scroll keeps its own ref array here (independent from the side
* `LyricsPanel`, which scrolls in parallel). A clean miss renders a
* discreet "No lyrics β Import / Fetch" CTA rather than vanishing, so
* the column width stays stable across track changes.
*/
export function ImmersiveLyricsColumn({
track,
payload,
lrcLines,
isSynced,
activeIndex,
activeWordIndex,
isFetching,
error,
staticText,
isRadio,
onSeek,
onImport,
onRefetch,
showHeader = true,
onCoverClick,
}: ImmersiveLyricsColumnProps) {
const { t } = useTranslation();
// Per-profile opt-in (#168). Default OFF β see the hook.
const { centered: syncCentered } = useFullscreenLyricsCentering();
const lineRefs = useRef<Array<HTMLLIElement | null>>([]);
// Keep the active line vertically centered. Own ref array so this
// scroller and the side panel can scroll independently.
useEffect(() => {
if (!isSynced || activeIndex < 0) return;
const node = lineRefs.current[activeIndex];
if (node) {
node.scrollIntoView({ behavior: "smooth", block: "center" });
}
}, [activeIndex, isSynced]);
return (
<div className="h-full flex flex-col text-white">
{showHeader && (
<div className="px-8 pt-8 pb-4 shrink-0 flex items-center gap-4">
{onCoverClick ? (
<button
type="button"
onClick={onCoverClick}
aria-label={t("playerBar.nowPlaying")}
title={t("playerBar.nowPlaying")}
className="shrink-0 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-white/70"
>
<Artwork
path={track.artwork_path}
path1x={track.artwork_path_1x}
path2x={track.artwork_path_2x}
size="1x"
className="w-14 h-14 shadow-lg"
iconSize={20}
alt={track.title}
rounded="lg"
/>
</button>
) : (
<Artwork
path={track.artwork_path}
path1x={track.artwork_path_1x}
path2x={track.artwork_path_2x}
size="1x"
className="w-14 h-14 shadow-lg shrink-0"
iconSize={20}
alt={track.title}
rounded="lg"
/>
)}
<div className="min-w-0">
<div className="text-xs uppercase tracking-[0.2em] text-white/40">
{t("lyrics.title")}
</div>
<div className="text-base font-bold text-white truncate">
{track.title}
</div>
<div className="text-sm text-white/50 truncate">
{track.artist_name ?? "β"}
</div>
</div>
</div>
)}
<div className="flex-1 overflow-y-auto px-8 scroll-smooth">
<div className="max-w-3xl mx-auto">
{isFetching && !payload ? (
<CenteredMessage text={t("lyrics.loading")} />
) : error ? (
<CenteredMessage
icon={<AlertCircle size={56} />}
text={t("lyrics.fetchError")}
/>
) : !payload || payload.content.trim() === "" ? (
<CenteredMessage
icon={<Music2 size={56} />}
text={t("lyrics.notFound")}
// Discreet recovery CTA β hidden for radio (no library row
// to import-to / refetch-for).
actions={
isRadio ? undefined : (
<div className="mt-5 flex items-center justify-center gap-3">
<button
type="button"
onClick={onImport}
className="flex items-center gap-2 px-4 py-2 rounded-full bg-white/10 hover:bg-white/20 transition-colors text-sm"
>
<Upload size={15} />
{t("lyrics.actions.import")}
</button>
<button
type="button"
onClick={onRefetch}
disabled={isFetching}
className="flex items-center gap-2 px-4 py-2 rounded-full bg-white/10 hover:bg-white/20 transition-colors text-sm disabled:opacity-50"
>
<RefreshCcw
size={15}
className={isFetching ? "animate-spin" : ""}
/>
{t("lyrics.actions.refetch")}
</button>
</div>
)
}
/>
) : isSynced ? (
<ul className="py-[40vh] space-y-6">
{lrcLines.map((line, index) => {
const distance = Math.abs(index - activeIndex);
const isActive = index === activeIndex;
const isPast = index < activeIndex;
// Smooth fade based on distance from the active line β
// feels like Apple Music's lyrics view.
const opacity = isActive
? 1
: Math.max(0.18, 0.7 - distance * 0.08);
const hasWords = isActive && (line.words?.length ?? 0) > 0;
return (
<li
key={`${line.timeMs}-${index}`}
ref={(el) => {
lineRefs.current[index] = el;
}}
style={{ opacity }}
>
<button
type="button"
onClick={() => onSeek(line)}
className={`block w-full text-3xl md:text-4xl font-bold leading-snug cursor-pointer transition-all select-none focus:outline-none focus-visible:ring-2 focus-visible:ring-white/70 rounded ${
syncCentered ? "text-center" : "text-left"
} ${
isActive
? "text-white scale-[1.04]"
: isPast
? "text-white/40"
: "text-white/70 hover:text-white"
}`}
>
{hasWords ? (
<span>
{line.words!.map((word, wi) => {
const wState =
wi === activeWordIndex
? "active"
: wi < activeWordIndex
? "past"
: "future";
// Render a literal space between adjacent word
// boxes β `inline-block` strips the JSX
// whitespace and many Enhanced LRC sources omit
// spaces between word stamps.
return (
<Fragment key={wi}>
<span
style={{
opacity:
wState === "active"
? 1
: wState === "past"
? 0.8
: 0.45,
transform:
wState === "active"
? "scale(1.04)"
: "scale(1)",
display: "inline-block",
transition:
"opacity 150ms ease, transform 150ms ease",
}}
>
{word.text}
</span>
{wi < line.words!.length - 1 && " "}
</Fragment>
);
})}
</span>
) : (
line.text || " "
)}
</button>
</li>
);
})}
</ul>
) : (
<p className="text-2xl leading-relaxed text-white/90 whitespace-pre-line pt-16 pb-[40vh] text-center">
{staticText ?? payload.content}
</p>
)}
</div>
</div>
</div>
);
}
function CenteredMessage({
icon,
text,
actions,
}: {
icon?: React.ReactNode;
text: string;
actions?: React.ReactNode;
}) {
return (
<div className="h-[80vh] flex flex-col items-center justify-center text-center text-white/70">
{icon && <div className="mb-4">{icon}</div>}
<p className="text-lg">{text}</p>
{actions}
</div>
);
}