Commit e292025b authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Redesign FullPlayer to mirror real Spotify (no tabs)

Replaced the Cover/Lyrics/Queue tab switcher with Spotify's actual
pattern: cover art is always the primary now-playing screen, and
Lyrics/Queue are separate screens reached via a lyrics preview bar and
a queue icon respectively, sliding in from the right with their own
back button (push-navigation, not tab-switching). The lyrics preview
bar only appears when the track actually has lyrics, matching Spotify
rather than linking to a dead-end empty screen.

Escape now backs out one level at a time (Lyrics/Queue -> cover ->
close), and picking a track from the Queue screen returns you to the
now-playing screen instead of leaving you on the list.
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent 3578ac25
Pipeline #1047 canceled with stage
import { render, screen, waitFor } from '@testing-library/react' import { render, screen, waitFor, within } from '@testing-library/react'
import userEvent from '@testing-library/user-event' import userEvent from '@testing-library/user-event'
import { afterEach, describe, expect, it, vi } from 'vitest' import { afterEach, describe, expect, it, vi } from 'vitest'
import { PlayerProvider, usePlayer, type PlayableSong } from '../context/PlayerContext' import { PlayerProvider, usePlayer, type PlayableSong } from '../context/PlayerContext'
...@@ -6,17 +6,38 @@ import { NowPlayingBar } from './NowPlayingBar' ...@@ -6,17 +6,38 @@ import { NowPlayingBar } from './NowPlayingBar'
import { FullPlayer } from './FullPlayer' import { FullPlayer } from './FullPlayer'
import * as streamApi from '../api/stream' import * as streamApi from '../api/stream'
const SONG: PlayableSong = { const SONG_WITH_LYRICS: PlayableSong = {
id: 1, id: 1,
title: 'Test Song', title: 'Test Song',
artist: 'Test Artist', artist: 'Test Artist',
album: 'Test Album', album: 'Test Album',
lyrics: 'Line one\nLine two', lyrics: 'Line one\nLine two',
} }
const SONG_NO_LYRICS: PlayableSong = {
id: 2,
title: 'Instrumental',
artist: 'Test Artist',
lyrics: null,
}
function Probe() { function Probe() {
const { toggle } = usePlayer() const { toggle } = usePlayer()
return <button onClick={() => toggle(SONG)}>Start Playback</button> return (
<div>
<button onClick={() => toggle(SONG_WITH_LYRICS)}>Start Playback</button>
<button onClick={() => toggle(SONG_WITH_LYRICS, [SONG_WITH_LYRICS, SONG_NO_LYRICS])}>
Start Playback With Queue
</button>
{/* Simulates the current song changing out from under an open FullPlayer via some route
that isn't FullPlayer's own Next button - e.g. auto-advance on track end, or picking
a different song from another page - which is the scenario that actually matters for
"does the Lyrics screen react correctly", independent of whether Next itself is
reachable while that screen is open. */}
<button onClick={() => toggle(SONG_NO_LYRICS, [SONG_WITH_LYRICS, SONG_NO_LYRICS])}>
Switch To No-Lyrics Song
</button>
</div>
)
} }
function renderPlayer() { function renderPlayer() {
...@@ -29,35 +50,77 @@ function renderPlayer() { ...@@ -29,35 +50,77 @@ function renderPlayer() {
) )
} }
async function openFullPlayer() {
const openButton = await screen.findByRole('button', { name: /Open player/ })
await userEvent.click(openButton)
await waitFor(() => expect(screen.getByRole('button', { name: 'Minimize player' })).toHaveFocus())
return openButton
}
// NowPlayingBar is rendered alongside FullPlayer in every test here, and both have their own
// Play/Pause button once a song is loaded - scope queries to the dialog to disambiguate.
function dialog() {
return within(screen.getByRole('dialog'))
}
describe('FullPlayer', () => { describe('FullPlayer', () => {
afterEach(() => { afterEach(() => {
vi.restoreAllMocks() vi.restoreAllMocks()
}) })
it('opens from the mini player, focuses the minimize button, and shows lyrics on the Lyrics tab', async () => { it('opens from the mini player showing the cover art view by default', async () => {
vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url') vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url')
renderPlayer() renderPlayer()
await userEvent.click(screen.getByText('Start Playback')) await userEvent.click(screen.getByText('Start Playback'))
const openButton = await screen.findByRole('button', { name: /Open player/ }) await openFullPlayer()
await userEvent.click(openButton)
await screen.findByRole('dialog', { name: /Now playing: Test Song by Test Artist/ }) await screen.findByRole('dialog', { name: /Now playing: Test Song by Test Artist/ })
await waitFor(() => expect(screen.getByRole('button', { name: 'Minimize player' })).toHaveFocus()) // No tab switcher any more - cover/transport controls are just there, no navigation needed.
expect(screen.getByRole('tab', { name: /Cover/ })).toHaveAttribute('aria-selected', 'true') expect(dialog().getByRole('button', { name: 'Pause' })).toBeInTheDocument()
expect(dialog().getByRole('button', { name: 'Open queue' })).toBeInTheDocument()
})
it('opens Lyrics via the preview bar, and Back returns to the cover screen with focus restored', async () => {
vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url')
renderPlayer()
await userEvent.click(screen.getByText('Start Playback'))
await openFullPlayer()
const lyricsButton = screen.getByRole('button', { name: 'View lyrics' })
await userEvent.click(lyricsButton)
const lyricsRegion = await screen.findByRole('region', { name: 'Lyrics' })
expect(lyricsRegion).toHaveTextContent('Line one')
expect(lyricsRegion).toHaveTextContent('Line two')
await waitFor(() => expect(screen.getByRole('button', { name: 'Back to now playing' })).toHaveFocus())
await userEvent.click(screen.getByRole('button', { name: 'Back to now playing' }))
await waitFor(() => expect(lyricsButton).toHaveFocus())
})
it('falls back to an empty state if the current song changes to one with no lyrics while the Lyrics screen is open', async () => {
vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url')
renderPlayer()
await userEvent.click(screen.getByText('Start Playback'))
await openFullPlayer()
await userEvent.click(screen.getByRole('tab', { name: /Lyrics/ })) await userEvent.click(screen.getByRole('button', { name: 'View lyrics' }))
expect(await screen.findByText('Line one')).toBeInTheDocument()
expect(screen.getByRole('tab', { name: /Lyrics/ })).toHaveAttribute('aria-selected', 'true') await userEvent.click(screen.getByText('Switch To No-Lyrics Song'))
expect(screen.getByText(/Line one/)).toBeInTheDocument()
expect(await screen.findByText('No lyrics available for this track.')).toBeInTheDocument()
}) })
it('shows a clear empty state when a track has no lyrics', async () => { it('does not show a lyrics preview bar at all for a track with no lyrics', async () => {
vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url') vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url')
function ProbeNoLyrics() { function ProbeNoLyrics() {
const { toggle } = usePlayer() const { toggle } = usePlayer()
return <button onClick={() => toggle({ ...SONG, lyrics: null })}>Start Playback</button> return <button onClick={() => toggle(SONG_NO_LYRICS)}>Start Playback</button>
} }
render( render(
...@@ -69,26 +132,42 @@ describe('FullPlayer', () => { ...@@ -69,26 +132,42 @@ describe('FullPlayer', () => {
) )
await userEvent.click(screen.getByText('Start Playback')) await userEvent.click(screen.getByText('Start Playback'))
const openButton = await screen.findByRole('button', { name: /Open player/ }) await openFullPlayer()
await userEvent.click(openButton)
await waitFor(() => expect(screen.getByRole('button', { name: 'Minimize player' })).toHaveFocus()) expect(screen.queryByRole('button', { name: 'View lyrics' })).not.toBeInTheDocument()
})
it('opens the Queue via its icon and can jump straight to a queued track', async () => {
vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url')
renderPlayer()
await userEvent.click(screen.getByText('Start Playback With Queue'))
await openFullPlayer()
await userEvent.click(screen.getByRole('button', { name: 'Open queue' }))
expect(await screen.findByText('Instrumental')).toBeInTheDocument()
await userEvent.click(screen.getByRole('tab', { name: /Lyrics/ })) await userEvent.click(screen.getByText('Instrumental'))
expect(screen.getByText('No lyrics available for this track.')).toBeInTheDocument() await screen.findByRole('dialog', { name: /Now playing: Instrumental by Test Artist/ })
}) })
it('closes on Escape and returns focus to the control that opened it', async () => { it('closes on Escape (one level at a time) and returns focus to the control that opened it', async () => {
vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url') vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url')
renderPlayer() renderPlayer()
await userEvent.click(screen.getByText('Start Playback')) await userEvent.click(screen.getByText('Start Playback'))
const openButton = await screen.findByRole('button', { name: /Open player/ }) const openButton = await openFullPlayer()
await userEvent.click(openButton)
await waitFor(() => expect(screen.getByRole('button', { name: 'Minimize player' })).toHaveFocus())
await userEvent.click(screen.getByRole('button', { name: 'View lyrics' }))
await screen.findByText('Line one')
// First Escape only backs out of the Lyrics screen, not the whole player.
await userEvent.keyboard('{Escape}') await userEvent.keyboard('{Escape}')
await waitFor(() => expect(dialog().getByRole('button', { name: 'Pause' })).toBeInTheDocument())
expect(screen.getByRole('dialog')).toBeInTheDocument()
await userEvent.keyboard('{Escape}')
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument()) await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
await waitFor(() => expect(openButton).toHaveFocus()) await waitFor(() => expect(openButton).toHaveFocus())
}) })
......
import { useEffect, useRef, useState, type KeyboardEvent } from 'react' import { useEffect, useRef, useState } from 'react'
import { import {
AudioLines, AudioLines,
ChevronDown, ChevronDown,
Disc3, ChevronLeft,
ChevronRight,
ListMusic, ListMusic,
Music2, Music2,
Pause, Pause,
...@@ -13,7 +14,6 @@ import { ...@@ -13,7 +14,6 @@ import {
Shuffle, Shuffle,
SkipBack, SkipBack,
SkipForward, SkipForward,
type LucideIcon,
} from 'lucide-react' } from 'lucide-react'
import { usePlayer, type PlayableSong } from '../context/PlayerContext' import { usePlayer, type PlayableSong } from '../context/PlayerContext'
import { EmptyState } from './ui/EmptyState' import { EmptyState } from './ui/EmptyState'
...@@ -28,18 +28,14 @@ function formatTime(seconds: number): string { ...@@ -28,18 +28,14 @@ function formatTime(seconds: number): string {
return `${mins}:${secs.toString().padStart(2, '0')}` return `${mins}:${secs.toString().padStart(2, '0')}`
} }
const TABS: { id: 'cover' | 'lyrics' | 'queue'; label: string; icon: LucideIcon }[] = [ type SecondaryView = 'lyrics' | 'queue' | null
{ id: 'cover', label: 'Cover', icon: Disc3 },
{ id: 'lyrics', label: 'Lyrics', icon: ScrollText },
{ id: 'queue', label: 'Queue', icon: ListMusic },
]
type TabId = (typeof TABS)[number]['id']
/** Full-screen "Now Playing" view, opened from NowPlayingBar - mirrors the Spotify pattern /** Full-screen "Now Playing" view, opened from NowPlayingBar - mirrors Spotify's now-playing
* of a persistent mini-player that expands into a dedicated screen with transport controls, * screen: cover art is always the primary view, with Lyrics and Queue reached as separate
* a seek bar, and Cover/Lyrics/Queue views. Stays mounted for one extra animation frame after * screens that slide in from the right (a push-navigation feel, not a tab switcher) and slide
* closing so the exit transition can play (see useMountTransition), and is otherwise absent * back out on their own back button. Stays mounted for one extra animation frame after closing
* from the DOM - no hidden-but-focusable controls left behind. */ * so the exit transition can play (see useMountTransition), and is otherwise absent from the
* DOM - no hidden-but-focusable controls left behind. */
export function FullPlayer() { export function FullPlayer() {
const { const {
currentSong, currentSong,
...@@ -60,19 +56,37 @@ export function FullPlayer() { ...@@ -60,19 +56,37 @@ export function FullPlayer() {
toggleShuffle, toggleShuffle,
cycleRepeat, cycleRepeat,
} = usePlayer() } = usePlayer()
const [activeTab, setActiveTab] = useState<TabId>('cover') const [secondaryView, setSecondaryView] = useState<SecondaryView>(null)
const { mounted, visible } = useMountTransition(isExpanded && !!currentSong, ANIMATION_MS) const { mounted, visible } = useMountTransition(isExpanded && !!currentSong, ANIMATION_MS)
const collapseButtonRef = useRef<HTMLButtonElement>(null) const collapseButtonRef = useRef<HTMLButtonElement>(null)
const tabRefs = useRef<(HTMLButtonElement | null)[]>([]) const secondaryBackButtonRef = useRef<HTMLButtonElement>(null)
const lyricsButtonRef = useRef<HTMLButtonElement>(null)
const queueButtonRef = useRef<HTMLButtonElement>(null)
useEffect(() => { useEffect(() => {
if (visible) collapseButtonRef.current?.focus() if (visible) collapseButtonRef.current?.focus()
}, [visible]) }, [visible])
// Reset to the cover view every time the player is closed, so reopening it doesn't
// surprise you by landing back on Lyrics or Queue from last time.
useEffect(() => {
if (!visible) setSecondaryView(null)
}, [visible])
useEffect(() => {
if (secondaryView) secondaryBackButtonRef.current?.focus()
}, [secondaryView])
useEffect(() => { useEffect(() => {
if (!visible) return if (!visible) return
function onKeyDown(e: globalThis.KeyboardEvent) { function onKeyDown(e: globalThis.KeyboardEvent) {
if (e.key === 'Escape') collapse() if (e.key !== 'Escape') return
// Escape backs out one level at a time, same as the physical back button would.
setSecondaryView((current) => {
if (current) return null
collapse()
return current
})
} }
document.addEventListener('keydown', onKeyDown) document.addEventListener('keydown', onKeyDown)
return () => document.removeEventListener('keydown', onKeyDown) return () => document.removeEventListener('keydown', onKeyDown)
...@@ -89,41 +103,41 @@ export function FullPlayer() { ...@@ -89,41 +103,41 @@ export function FullPlayer() {
if (!mounted || !currentSong) return null if (!mounted || !currentSong) return null
function focusTab(index: number) { function openLyrics() {
const wrapped = (index + TABS.length) % TABS.length setSecondaryView('lyrics')
setActiveTab(TABS[wrapped].id)
tabRefs.current[wrapped]?.focus()
} }
function openQueue() {
function onTabKeyDown(e: KeyboardEvent<HTMLButtonElement>, index: number) { setSecondaryView('queue')
if (e.key === 'ArrowRight') {
e.preventDefault()
focusTab(index + 1)
} else if (e.key === 'ArrowLeft') {
e.preventDefault()
focusTab(index - 1)
} }
function closeSecondary() {
setSecondaryView(null)
;(secondaryView === 'lyrics' ? lyricsButtonRef : queueButtonRef).current?.focus()
} }
function jumpTo(song: PlayableSong) { function jumpTo(song: PlayableSong) {
toggle(song, queue) toggle(song, queue)
// Selecting a track from the queue returns to the main now-playing screen (matching
// Spotify), rather than leaving you stranded on the queue list you just picked from.
setSecondaryView(null)
collapseButtonRef.current?.focus()
} }
const pct = duration > 0 ? Math.min(100, (progress / duration) * 100) : 0 const pct = duration > 0 ? Math.min(100, (progress / duration) * 100) : 0
const RepeatIcon = repeatMode === 'one' ? Repeat1 : Repeat const RepeatIcon = repeatMode === 'one' ? Repeat1 : Repeat
const lyricsPreview = currentSong.lyrics?.split('\n').find((line) => line.trim().length > 0)
return ( return (
<div <div
role="dialog" role="dialog"
aria-modal="true" aria-modal="true"
aria-label={`Now playing: ${currentSong.title} by ${currentSong.artist}`} aria-label={`Now playing: ${currentSong.title} by ${currentSong.artist}`}
className={`fixed inset-0 z-30 flex flex-col overflow-hidden bg-neutral-950 text-white transition-all duration-300 ease-out motion-reduce:transition-none ${ className={`fixed inset-0 z-30 overflow-hidden bg-neutral-950 text-white transition-all duration-300 ease-out motion-reduce:transition-none ${
visible ? 'translate-y-0 opacity-100' : 'translate-y-6 opacity-0' visible ? 'translate-y-0 opacity-100' : 'translate-y-6 opacity-0'
}`} }`}
> >
{/* Large, blurred backdrop of the current cover art - fills the otherwise-empty space {/* Large, blurred backdrop of the current cover art - fills the otherwise-empty space
around a centered album cover with something alive, rather than flat black (the around a centered album cover with something alive, rather than flat black (the
Spotify/Apple Music "now playing" convention). Purely decorative. */} Spotify/Apple Music "now playing" convention). Purely decorative, shared by both the
primary and secondary screens beneath them. */}
<div className="pointer-events-none absolute inset-0" aria-hidden="true"> <div className="pointer-events-none absolute inset-0" aria-hidden="true">
{currentSong.coverart && ( {currentSong.coverart && (
<img <img
...@@ -135,6 +149,14 @@ export function FullPlayer() { ...@@ -135,6 +149,14 @@ export function FullPlayer() {
<div className="absolute inset-0 bg-neutral-950/75" /> <div className="absolute inset-0 bg-neutral-950/75" />
</div> </div>
{/* Primary screen: cover art, transport, and (if available) a lyrics preview bar. Slides
left and out of view when a secondary screen is open. */}
<div
className={`absolute inset-0 flex flex-col transition-transform duration-300 ease-out motion-reduce:transition-none ${
secondaryView ? '-translate-x-1/4 opacity-0' : 'translate-x-0 opacity-100'
}`}
aria-hidden={!!secondaryView}
>
<div <div
className="relative flex items-center justify-between px-4 pt-4 sm:px-6" className="relative flex items-center justify-between px-4 pt-4 sm:px-6"
style={{ paddingTop: 'calc(env(safe-area-inset-top) + 1rem)' }} style={{ paddingTop: 'calc(env(safe-area-inset-top) + 1rem)' }}
...@@ -142,57 +164,25 @@ export function FullPlayer() { ...@@ -142,57 +164,25 @@ export function FullPlayer() {
<button <button
ref={collapseButtonRef} ref={collapseButtonRef}
onClick={collapse} onClick={collapse}
tabIndex={secondaryView ? -1 : 0}
aria-label="Minimize player" aria-label="Minimize player"
className="flex h-10 w-10 items-center justify-center rounded-full text-neutral-400 transition-colors hover:bg-white/10 hover:text-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400" className="flex h-10 w-10 items-center justify-center rounded-full text-neutral-400 transition-colors hover:bg-white/10 hover:text-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400"
> >
<ChevronDown size={22} strokeWidth={2} /> <ChevronDown size={22} strokeWidth={2} />
</button> </button>
<p className="text-xs font-medium uppercase tracking-wide text-neutral-500">Now Playing</p> <p className="text-xs font-medium uppercase tracking-wide text-neutral-500">Now Playing</p>
<div className="h-10 w-10" aria-hidden="true" />
</div>
<div role="tablist" aria-label="Now playing view" className="relative mx-auto mt-3 flex gap-1 rounded-full bg-white/5 p-1">
{TABS.map((tab, index) => {
const active = activeTab === tab.id
const Icon = tab.icon
return (
<button <button
key={tab.id} ref={queueButtonRef}
ref={(el) => { onClick={openQueue}
tabRefs.current[index] = el tabIndex={secondaryView ? -1 : 0}
}} aria-label="Open queue"
role="tab" className="flex h-10 w-10 items-center justify-center rounded-full text-neutral-400 transition-colors hover:bg-white/10 hover:text-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400"
id={`player-tab-${tab.id}`}
aria-selected={active}
aria-controls={`player-panel-${tab.id}`}
tabIndex={active ? 0 : -1}
onClick={() => setActiveTab(tab.id)}
onKeyDown={(e) => onTabKeyDown(e, index)}
className={`flex items-center gap-1.5 rounded-full px-3.5 py-1.5 text-sm font-medium transition-colors duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400 ${
active ? 'bg-neutral-100 text-neutral-950' : 'text-neutral-400 hover:text-white'
}`}
> >
<Icon size={14} strokeWidth={2} /> <ListMusic size={19} strokeWidth={2} />
{tab.label}
</button> </button>
)
})}
</div> </div>
<div className="relative mx-auto w-full max-w-md flex-1 overflow-hidden px-6 py-5"> <div className="relative mx-auto flex w-full max-w-md flex-1 items-center justify-center px-8 py-4">
{/* None of the three panels below contain focusable content (decorative image, plain
lyrics text, or a queue list that's only rendered while its own tab is active), so
it's safe to crossfade Cover/Lyrics with opacity instead of snap-toggling via the
`hidden` attribute - aria-hidden keeps the inactive one out of the a11y tree. */}
<div
id="player-panel-cover"
role="tabpanel"
aria-labelledby="player-tab-cover"
aria-hidden={activeTab !== 'cover'}
className={`absolute inset-4 flex items-center justify-center transition-opacity duration-300 ease-out motion-reduce:transition-none ${
activeTab === 'cover' ? 'opacity-100' : 'pointer-events-none opacity-0'
}`}
>
{currentSong.coverart ? ( {currentSong.coverart ? (
<img <img
src={currentSong.coverart} src={currentSong.coverart}
...@@ -213,75 +203,7 @@ export function FullPlayer() { ...@@ -213,75 +203,7 @@ export function FullPlayer() {
</div> </div>
<div <div
id="player-panel-lyrics" className="relative mx-auto w-full max-w-md px-6 pb-6 sm:pb-8"
role="tabpanel"
aria-labelledby="player-tab-lyrics"
aria-hidden={activeTab !== 'lyrics'}
className={`absolute inset-0 overflow-y-auto rounded-2xl bg-white/5 px-5 py-8 transition-opacity duration-300 ease-out motion-reduce:transition-none ${
activeTab === 'lyrics' ? 'opacity-100' : 'pointer-events-none opacity-0'
}`}
style={{
maskImage: 'linear-gradient(to bottom, transparent, black 24px, black calc(100% - 24px), transparent)',
WebkitMaskImage:
'linear-gradient(to bottom, transparent, black 24px, black calc(100% - 24px), transparent)',
}}
>
{currentSong.lyrics ? (
<p className="whitespace-pre-wrap text-[17px] leading-loose text-neutral-200">{currentSong.lyrics}</p>
) : (
<EmptyState icon={ScrollText} message="No lyrics available for this track." />
)}
</div>
<div
id="player-panel-queue"
role="tabpanel"
aria-labelledby="player-tab-queue"
aria-hidden={activeTab !== 'queue'}
className={`absolute inset-0 overflow-y-auto transition-opacity duration-300 ease-out motion-reduce:transition-none ${
activeTab === 'queue' ? 'opacity-100' : 'pointer-events-none opacity-0'
}`}
>
{queue.length === 0 ? (
<EmptyState icon={ListMusic} message="Nothing queued." />
) : (
<ul>
{queue.map((song, index) => {
const isCurrent = song.id === currentSong.id
return (
<li key={song.id}>
<button
onClick={() => jumpTo(song)}
aria-current={isCurrent ? 'true' : undefined}
className={`flex w-full items-center gap-3 rounded-lg px-2 py-2.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400 ${
isCurrent ? 'text-emerald-400' : 'text-neutral-300 hover:bg-white/5 hover:text-white'
}`}
>
<span className="flex w-5 shrink-0 items-center justify-center text-xs text-neutral-500">
{isCurrent ? <AudioLines size={15} strokeWidth={2} /> : index + 1}
</span>
{song.coverart ? (
<img src={song.coverart} alt="" className="h-10 w-10 shrink-0 rounded-md object-cover" />
) : (
<div className="flex h-10 w-10 shrink-0 items-center justify-center rounded-md bg-neutral-800 text-neutral-600">
<Music2 size={15} strokeWidth={1.75} />
</div>
)}
<div className="min-w-0 flex-1">
<p className="truncate text-sm font-medium">{song.title}</p>
<p className="truncate text-xs text-neutral-500">{song.artist}</p>
</div>
</button>
</li>
)
})}
</ul>
)}
</div>
</div>
<div
className="relative mx-auto w-full max-w-md border-t border-white/5 px-6 pt-5 pb-6 sm:pb-8"
style={{ paddingBottom: 'calc(env(safe-area-inset-bottom) + 1.5rem)' }} style={{ paddingBottom: 'calc(env(safe-area-inset-bottom) + 1.5rem)' }}
> >
<div className="mb-5"> <div className="mb-5">
...@@ -300,6 +222,7 @@ export function FullPlayer() { ...@@ -300,6 +222,7 @@ export function FullPlayer() {
step={0.1} step={0.1}
onChange={(e) => seek(Number(e.target.value))} onChange={(e) => seek(Number(e.target.value))}
disabled={!duration} disabled={!duration}
tabIndex={secondaryView ? -1 : 0}
aria-label="Seek" aria-label="Seek"
aria-valuetext={`${formatTime(progress)} of ${formatTime(duration)}`} aria-valuetext={`${formatTime(progress)} of ${formatTime(duration)}`}
className="seek-range w-full disabled:opacity-40" className="seek-range w-full disabled:opacity-40"
...@@ -319,6 +242,7 @@ export function FullPlayer() { ...@@ -319,6 +242,7 @@ export function FullPlayer() {
<div className="mt-5 flex items-center justify-between"> <div className="mt-5 flex items-center justify-between">
<button <button
onClick={toggleShuffle} onClick={toggleShuffle}
tabIndex={secondaryView ? -1 : 0}
aria-label="Shuffle" aria-label="Shuffle"
aria-pressed={isShuffled} aria-pressed={isShuffled}
className={`rounded-full p-2 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400 ${ className={`rounded-full p-2 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400 ${
...@@ -331,6 +255,7 @@ export function FullPlayer() { ...@@ -331,6 +255,7 @@ export function FullPlayer() {
<div className="flex items-center gap-8"> <div className="flex items-center gap-8">
<button <button
onClick={previous} onClick={previous}
tabIndex={secondaryView ? -1 : 0}
aria-label="Previous" aria-label="Previous"
className="rounded-full p-1 text-neutral-300 transition-colors hover:text-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400" className="rounded-full p-1 text-neutral-300 transition-colors hover:text-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400"
> >
...@@ -339,6 +264,7 @@ export function FullPlayer() { ...@@ -339,6 +264,7 @@ export function FullPlayer() {
<button <button
onClick={() => toggle(currentSong)} onClick={() => toggle(currentSong)}
disabled={isLoading} disabled={isLoading}
tabIndex={secondaryView ? -1 : 0}
aria-label={isPlaying ? 'Pause' : 'Play'} aria-label={isPlaying ? 'Pause' : 'Play'}
className="flex h-16 w-16 items-center justify-center rounded-full bg-white text-neutral-950 transition-transform duration-150 ease-out active:scale-90 disabled:opacity-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400 focus-visible:ring-offset-2 focus-visible:ring-offset-neutral-950" className="flex h-16 w-16 items-center justify-center rounded-full bg-white text-neutral-950 transition-transform duration-150 ease-out active:scale-90 disabled:opacity-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400 focus-visible:ring-offset-2 focus-visible:ring-offset-neutral-950"
> >
...@@ -353,6 +279,7 @@ export function FullPlayer() { ...@@ -353,6 +279,7 @@ export function FullPlayer() {
<button <button
onClick={next} onClick={next}
disabled={!hasNext} disabled={!hasNext}
tabIndex={secondaryView ? -1 : 0}
aria-label="Next" aria-label="Next"
className="rounded-full p-1 text-neutral-300 transition-colors hover:text-white disabled:opacity-30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400" className="rounded-full p-1 text-neutral-300 transition-colors hover:text-white disabled:opacity-30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400"
> >
...@@ -362,6 +289,7 @@ export function FullPlayer() { ...@@ -362,6 +289,7 @@ export function FullPlayer() {
<button <button
onClick={cycleRepeat} onClick={cycleRepeat}
tabIndex={secondaryView ? -1 : 0}
aria-label={`Repeat: ${repeatMode}`} aria-label={`Repeat: ${repeatMode}`}
aria-pressed={repeatMode !== 'off'} aria-pressed={repeatMode !== 'off'}
className={`rounded-full p-2 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400 ${ className={`rounded-full p-2 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400 ${
...@@ -371,6 +299,108 @@ export function FullPlayer() { ...@@ -371,6 +299,108 @@ export function FullPlayer() {
<RepeatIcon size={18} strokeWidth={2} /> <RepeatIcon size={18} strokeWidth={2} />
</button> </button>
</div> </div>
{/* Lyrics preview bar - a single representative line, tappable to open the full
Lyrics screen. Only shown when the track actually has lyrics, matching Spotify
(which hides this row entirely rather than linking to an empty screen). */}
{lyricsPreview && (
<button
ref={lyricsButtonRef}
onClick={openLyrics}
tabIndex={secondaryView ? -1 : 0}
aria-label="View lyrics"
className="mt-5 flex w-full items-center gap-2 rounded-xl bg-white/5 px-4 py-3 text-left transition-colors hover:bg-white/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400"
>
<ScrollText size={15} strokeWidth={2} className="shrink-0 text-neutral-400" />
<span className="min-w-0 flex-1 truncate text-sm text-neutral-300">{lyricsPreview}</span>
<ChevronRight size={16} strokeWidth={2} className="shrink-0 text-neutral-500" />
</button>
)}
</div>
</div>
{/* Secondary screen: Lyrics or Queue, pushed in from the right with its own header. */}
<div
className={`absolute inset-0 flex flex-col transition-transform duration-300 ease-out motion-reduce:transition-none ${
secondaryView ? 'translate-x-0' : 'translate-x-full'
}`}
aria-hidden={!secondaryView}
>
<div
className="relative flex items-center gap-3 px-4 pt-4 sm:px-6"
style={{ paddingTop: 'calc(env(safe-area-inset-top) + 1rem)' }}
>
<button
ref={secondaryBackButtonRef}
onClick={closeSecondary}
tabIndex={secondaryView ? 0 : -1}
aria-label="Back to now playing"
className="flex h-10 w-10 items-center justify-center rounded-full text-neutral-400 transition-colors hover:bg-white/10 hover:text-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400"
>
<ChevronLeft size={22} strokeWidth={2} />
</button>
<p className="text-sm font-semibold">{secondaryView === 'lyrics' ? 'Lyrics' : 'Queue'}</p>
</div>
{secondaryView === 'lyrics' && (
<div
role="region"
aria-label="Lyrics"
className="relative mx-auto w-full max-w-md flex-1 overflow-y-auto px-6 py-6"
style={{
maskImage: 'linear-gradient(to bottom, transparent, black 24px, black calc(100% - 24px), transparent)',
WebkitMaskImage:
'linear-gradient(to bottom, transparent, black 24px, black calc(100% - 24px), transparent)',
}}
>
{currentSong.lyrics ? (
<p className="whitespace-pre-wrap text-[17px] leading-loose text-neutral-200">{currentSong.lyrics}</p>
) : (
<EmptyState icon={ScrollText} message="No lyrics available for this track." />
)}
</div>
)}
{secondaryView === 'queue' && (
<div className="relative mx-auto w-full max-w-md flex-1 overflow-y-auto px-4 py-4">
{queue.length === 0 ? (
<EmptyState icon={ListMusic} message="Nothing queued." />
) : (
<ul>
{queue.map((song, index) => {
const isCurrent = song.id === currentSong.id
return (
<li key={song.id}>
<button
onClick={() => jumpTo(song)}
tabIndex={secondaryView === 'queue' ? 0 : -1}
aria-current={isCurrent ? 'true' : undefined}
className={`flex w-full items-center gap-3 rounded-lg px-2 py-2.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400 ${
isCurrent ? 'text-emerald-400' : 'text-neutral-300 hover:bg-white/5 hover:text-white'
}`}
>
<span className="flex w-5 shrink-0 items-center justify-center text-xs text-neutral-500">
{isCurrent ? <AudioLines size={15} strokeWidth={2} /> : index + 1}
</span>
{song.coverart ? (
<img src={song.coverart} alt="" className="h-10 w-10 shrink-0 rounded-md object-cover" />
) : (
<div className="flex h-10 w-10 shrink-0 items-center justify-center rounded-md bg-neutral-800 text-neutral-600">
<Music2 size={15} strokeWidth={1.75} />
</div>
)}
<div className="min-w-0 flex-1">
<p className="truncate text-sm font-medium">{song.title}</p>
<p className="truncate text-xs text-neutral-500">{song.artist}</p>
</div>
</button>
</li>
)
})}
</ul>
)}
</div>
)}
</div> </div>
</div> </div>
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment