A Playlists page lists the user's playlists and makes a new one. A playlist has its own page: play it (songs that are not available are skipped), rename it, delete it after a confirmation, move a song up or down and take one out. Every song of a list gets an Add to playlist button that opens a window to choose a playlist or make a new one, and says what it did. TrackRow keeps the song as one button and takes extra buttons at its end, so the add button is not inside the button that plays. A long playlist is read whole, page after page. English and Italian texts, error texts for the new codes. Closes #92
49 lines
2.1 KiB
TypeScript
49 lines
2.1 KiB
TypeScript
import type { ReactNode } from 'react'
|
|
import type { Track } from '@/api/catalog'
|
|
import { formatTime } from '@/lib/time'
|
|
import { cn } from '@/lib/utils'
|
|
|
|
interface TrackRowProps {
|
|
track: Track
|
|
/** Position in the list, shown when the track has no number of its own. */
|
|
index: number
|
|
onPlay(): void
|
|
/** The track that is playing now. */
|
|
active?: boolean
|
|
/** The song cannot be played now: it is shown, and clicking it does nothing. */
|
|
disabled?: boolean
|
|
/** A short note under the title, for a song that needs one ("Not available"). */
|
|
note?: string
|
|
/** Buttons at the end of the row. They are not part of the button that plays the song. */
|
|
trailing?: ReactNode
|
|
}
|
|
|
|
/** One song in a list: number, title, artists and length. Clicking it plays it. */
|
|
export default function TrackRow({ track, index, onPlay, active = false, disabled = false, note, trailing }: TrackRowProps) {
|
|
const artists = track.artists.map((a) => a.name).join(', ') || '—'
|
|
return (
|
|
<div className={cn('flex items-center rounded-lg hover:bg-secondary', active && 'bg-secondary')}>
|
|
<button
|
|
type="button"
|
|
onClick={onPlay}
|
|
disabled={disabled}
|
|
aria-current={active ? 'true' : undefined}
|
|
className={cn(
|
|
'grid min-h-13 min-w-0 flex-1 grid-cols-[2.5rem_minmax(0,1fr)_4.5rem] items-center gap-3 rounded-lg px-4 text-left',
|
|
disabled && 'opacity-60',
|
|
)}
|
|
>
|
|
<span className={cn('tabular-nums', active ? 'font-bold text-primary' : 'text-muted-foreground')}>
|
|
{track.track_no > 0 ? track.track_no : index + 1}
|
|
</span>
|
|
<span className="min-w-0">
|
|
<span className={cn('block truncate font-semibold', active && 'text-primary')}>{track.title}</span>
|
|
<span className="block truncate text-sm text-muted-foreground">{artists}</span>
|
|
{note && <span className="block truncate text-sm text-destructive">{note}</span>}
|
|
</span>
|
|
<span className="text-right text-sm tabular-nums text-muted-foreground">{formatTime(track.duration_ms)}</span>
|
|
</button>
|
|
{trailing}
|
|
</div>
|
|
)
|
|
}
|