Commit 7c321a44 authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Spotify-style album grid + all-songs view on Library's default page

The default (non-search) view was a flat song list even though
/library/search already derived a proper Albums grouping for search
results. Adds the same grouping to the default view - computed
client-side from the already-loaded library (mirroring the backend's
own (album, artist) logic) rather than adding a redundant endpoint -
as a cover-art card grid above an always-visible All Songs list.
Tapping a card expands its tracks, same interaction search's album
rows already use. Verified visually with dev-test-user's real library
via Playwright (mobile + desktop) before shipping.
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent 04d2c5c1
Pipeline #1159 failed with stage
in 20 minutes and 10 seconds
...@@ -73,6 +73,52 @@ describe('Library', () => { ...@@ -73,6 +73,52 @@ describe('Library', () => {
expect(screen.getByText('Duran Duran · Astronaut')).toBeInTheDocument() expect(screen.getByText('Duran Duran · Astronaut')).toBeInTheDocument()
}) })
it('groups songs with an album into an Albums grid, alongside the full All Songs list', async () => {
const songWithoutAlbum = { ...SONG, id: 3, title: 'B-Side', album: null }
vi.spyOn(libraryApi, 'getLibrary').mockResolvedValue({ status: 'success', library: [SONG, songWithoutAlbum] })
renderLibrary()
const albumsHeading = await screen.findByRole('heading', { name: 'Albums' })
const albumsGrid = albumsHeading.nextElementSibling as HTMLElement
expect(within(albumsGrid).getByRole('button', { name: /Astronaut/ })).toBeInTheDocument()
// Only songs with an album form a card - one with no album doesn't get a stray card of its own.
expect(within(albumsGrid).queryByText('B-Side')).not.toBeInTheDocument()
const allSongsSection = screen.getByRole('heading', { name: 'All Songs' }).closest('div')!
expect(within(allSongsSection).getByText('Invisible')).toBeInTheDocument()
expect(within(allSongsSection).getByText('B-Side')).toBeInTheDocument()
})
it('does not show an Albums section when no library song has an album', async () => {
vi.spyOn(libraryApi, 'getLibrary').mockResolvedValue({
status: 'success',
library: [{ ...SONG, album: null }],
})
renderLibrary()
await screen.findByText('Invisible')
expect(screen.queryByRole('heading', { name: 'Albums' })).not.toBeInTheDocument()
})
it('expands an album card from the default view to show and play its tracks', async () => {
vi.spyOn(libraryApi, 'getLibrary').mockResolvedValue({ status: 'success', library: [SONG] })
const fetchStreamUrl = vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url')
renderLibrary()
await userEvent.click(await screen.findByRole('button', { name: /Astronaut/ }))
const allSongsSection = screen.getByRole('heading', { name: 'All Songs' }).closest('div')!
// Two "Invisible" rows now exist - one in the expanded album, one in All Songs - so play
// the one inside the album's own track list specifically.
const trackRows = screen.getAllByText('Invisible').map((el) => el.closest('li')!)
const albumTrackRow = trackRows.find((row) => !allSongsSection.contains(row))!
await userEvent.click(within(albumTrackRow).getByRole('button', { name: 'Play' }))
await waitFor(() => expect(fetchStreamUrl).toHaveBeenCalledWith(1))
})
it('shows a load error using the ApiError message', async () => { it('shows a load error using the ApiError message', async () => {
vi.spyOn(libraryApi, 'getLibrary').mockRejectedValue(new ApiError(500, 'Server exploded', null)) vi.spyOn(libraryApi, 'getLibrary').mockRejectedValue(new ApiError(500, 'Server exploded', null))
...@@ -241,8 +287,10 @@ describe('Library', () => { ...@@ -241,8 +287,10 @@ describe('Library', () => {
expect(confirmSpy).toHaveBeenCalledWith(expect.stringContaining('Invisible')) expect(confirmSpy).toHaveBeenCalledWith(expect.stringContaining('Invisible'))
await waitFor(() => expect(deleteLibrarySong).toHaveBeenCalledWith(1)) await waitFor(() => expect(deleteLibrarySong).toHaveBeenCalledWith(1))
await waitFor(() => expect(screen.queryByText('Invisible')).not.toBeInTheDocument()) await waitFor(() => expect(screen.queryByText('Invisible')).not.toBeInTheDocument())
// The other song is untouched. // The other song is untouched - scoped to the All Songs list since SONG_2's title and
expect(screen.getByText('Rio')).toBeInTheDocument() // album are both "Rio" in this fixture, which now also matches its own Albums grid card.
const allSongsSection = screen.getByRole('heading', { name: 'All Songs' }).closest('div')!
expect(within(allSongsSection).getByText('Rio')).toBeInTheDocument()
}) })
it('does not delete when the confirm dialog is dismissed', async () => { it('does not delete when the confirm dialog is dismissed', async () => {
......
import { useEffect, useState } from 'react' import { useEffect, useMemo, useState } from 'react'
import { ListMusic, ListPlus, Music2, Pause, Play, Search, Trash2 } from 'lucide-react' import { ListMusic, ListPlus, Music2, Pause, Play, Search, Trash2 } from 'lucide-react'
import { deleteLibrarySong, getLibrary, searchLibrary, type AlbumMatch, type LibrarySong } from '../api/library' import { deleteLibrarySong, getLibrary, searchLibrary, type AlbumMatch, type LibrarySong } from '../api/library'
import { ApiError } from '../api/client' import { ApiError } from '../api/client'
...@@ -137,6 +137,54 @@ function albumKey(album: AlbumMatch): string { ...@@ -137,6 +137,54 @@ function albumKey(album: AlbumMatch): string {
return `${album.album}::${album.artist}` return `${album.album}::${album.artist}`
} }
/** Client-side mirror of /library/search's (album, artist) grouping - the default library view
* needs the same album grid the search results get, but there's no reason to round-trip to the
* backend for it: the full song list (with each song's own album/coverart) is already loaded,
* so it's derived here instead of adding a second endpoint that returns the same shape. Skips
* songs with no album, same as the backend does. */
function groupIntoAlbums(songs: LibrarySong[]): AlbumMatch[] {
const byKey = new Map<string, AlbumMatch>()
for (const song of songs) {
if (!song.album) continue
const key = `${song.album}::${song.artist}`
const entry = byKey.get(key)
if (entry) {
entry.songs.push(song)
entry.track_count += 1
if (!entry.coverart && song.coverart) entry.coverart = song.coverart
} else {
byKey.set(key, { album: song.album, artist: song.artist, coverart: song.coverart, track_count: 1, songs: [song] })
}
}
return Array.from(byKey.values())
}
function AlbumCard({ album, expanded, onToggle }: { album: AlbumMatch; expanded: boolean; onToggle: () => void }) {
return (
<button
onClick={onToggle}
aria-expanded={expanded}
className={`flex min-w-0 flex-col gap-2 rounded-xl border p-3 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary ${
expanded ? 'border-primary bg-surface-container' : 'border-transparent hover:border-outline-variant hover:bg-surface-container'
}`}
>
{album.coverart ? (
<img src={album.coverart} alt="" className="aspect-square w-full rounded-lg object-cover" />
) : (
<div className="flex aspect-square w-full items-center justify-center rounded-lg bg-surface-container-high text-on-surface-variant">
<Music2 size={28} strokeWidth={1.5} />
</div>
)}
<div className="min-w-0">
<p className="truncate text-sm font-medium text-on-surface">{album.album}</p>
<p className="truncate text-xs text-on-surface-variant">
{album.artist} · {album.track_count} track{album.track_count === 1 ? '' : 's'}
</p>
</div>
</button>
)
}
export function Library() { export function Library() {
const [songs, setSongs] = useState<LibrarySong[]>([]) const [songs, setSongs] = useState<LibrarySong[]>([])
const [loading, setLoading] = useState(true) const [loading, setLoading] = useState(true)
...@@ -149,6 +197,9 @@ export function Library() { ...@@ -149,6 +197,9 @@ export function Library() {
const [searching, setSearching] = useState(false) const [searching, setSearching] = useState(false)
const [expandedAlbum, setExpandedAlbum] = useState<string | null>(null) const [expandedAlbum, setExpandedAlbum] = useState<string | null>(null)
const albums = useMemo(() => groupIntoAlbums(songs), [songs])
const expandedAlbumData = albums.find((a) => albumKey(a) === expandedAlbum) ?? null
useEffect(() => { useEffect(() => {
getLibrary() getLibrary()
.then((res) => setSongs(res.library)) .then((res) => setSongs(res.library))
...@@ -287,11 +338,50 @@ export function Library() { ...@@ -287,11 +338,50 @@ export function Library() {
)} )}
</> </>
) : ( ) : (
<>
{albums.length > 0 && (
<div className="mb-8">
<h2 className="mb-3 text-xs font-semibold uppercase tracking-[0.1em] text-primary">Albums</h2>
<div className="grid grid-cols-2 gap-3 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5">
{albums.map((album) => {
const key = albumKey(album)
return (
<AlbumCard
key={key}
album={album}
expanded={expandedAlbum === key}
onToggle={() => setExpandedAlbum(expandedAlbum === key ? null : key)}
/>
)
})}
</div>
{expandedAlbumData && (
<ul className="mt-3 space-y-1">
{expandedAlbumData.songs.map((s) => (
<SongRow
key={s.id}
song={s}
queue={expandedAlbumData.songs}
onAddToPlaylist={setAddingSong}
onDelete={handleDelete}
/>
))}
</ul>
)}
</div>
)}
{songs.length > 0 && (
<div>
<h2 className="mb-2 text-xs font-semibold uppercase tracking-[0.1em] text-primary">All Songs</h2>
<ul className="space-y-1"> <ul className="space-y-1">
{songs.map((song) => ( {songs.map((song) => (
<SongRow key={song.id} song={song} queue={songs} onAddToPlaylist={setAddingSong} onDelete={handleDelete} /> <SongRow key={song.id} song={song} queue={songs} onAddToPlaylist={setAddingSong} onDelete={handleDelete} />
))} ))}
</ul> </ul>
</div>
)}
</>
)} )}
{addingSong && <AddToPlaylistModal song={addingSong} onClose={() => setAddingSong(null)} />} {addingSong && <AddToPlaylistModal song={addingSong} onClose={() => setAddingSong(null)} />}
......
...@@ -189,6 +189,7 @@ const FRONTEND_DONE: DoneGroup[] = [ ...@@ -189,6 +189,7 @@ const FRONTEND_DONE: DoneGroup[] = [
'Library page with playback', 'Library page with playback',
'Real-time synced lyrics in the full-screen player (2026-08-31): line-by-line highlight follows playback position (last line whose timestamp has passed), auto-scrolls the active line to center, tapping a line seeks there - Spotify\'s actual signature lyrics behavior, not an approximation. Falls back to the existing static full-text view when a song has plain lyrics but no synced timing, and to the empty state when it has neither. Fixed same day: the synced-lyrics lookup was only attempted when the identification candidate itself had no plain lyrics already - but Shazam and Gemini can both independently return a plain snippet, which was silently skipping the sync fetch (and any real timing that existed) whenever that happened. Now always attempted, with synced data winning over the candidate\'s own plain text when found; existing library songs were backfilled', 'Real-time synced lyrics in the full-screen player (2026-08-31): line-by-line highlight follows playback position (last line whose timestamp has passed), auto-scrolls the active line to center, tapping a line seeks there - Spotify\'s actual signature lyrics behavior, not an approximation. Falls back to the existing static full-text view when a song has plain lyrics but no synced timing, and to the empty state when it has neither. Fixed same day: the synced-lyrics lookup was only attempted when the identification candidate itself had no plain lyrics already - but Shazam and Gemini can both independently return a plain snippet, which was silently skipping the sync fetch (and any real timing that existed) whenever that happened. Now always attempted, with synced data winning over the candidate\'s own plain text when found; existing library songs were backfilled',
'Universal search box: separate Songs and Albums result sections while searching (an album expands to show/play its tracks) - replaces the plain list rather than filtering it in place', 'Universal search box: separate Songs and Albums result sections while searching (an album expands to show/play its tracks) - replaces the plain list rather than filtering it in place',
'Spotify-style default (non-search) view (2026-09-01): an Albums grid of cover-art cards above an always-on All Songs list covering the full library. The (album, artist) grouping is derived client-side from the already-loaded song list (mirroring /library/search\'s own grouping) rather than adding a second backend endpoint that would return the same shape - deletions and new songs update both sections for free since All Songs and the album groups both derive from the same one songs array. Tapping a card expands its tracks below the grid, same interaction as search\'s album rows.',
'Playlists page: list, create, view tracks, playback', 'Playlists page: list, create, view tracks, playback',
'Add-to-playlist modal from the Library page (add existing or create-and-add)', 'Add-to-playlist modal from the Library page (add existing or create-and-add)',
'Delete-from-library (2026-08-31): swipe a Library row left past a threshold to reveal and trigger delete (right instead adds to queue) - confirms via the same window.confirm pattern already used for soundmark delete, then removes the file on disk and reconciles the song out of every local list it could be showing in (the full library, the current search\'s Songs section, and any album groupings within it)', 'Delete-from-library (2026-08-31): swipe a Library row left past a threshold to reveal and trigger delete (right instead adds to queue) - confirms via the same window.confirm pattern already used for soundmark delete, then removes the file on disk and reconciles the song out of every local list it could be showing in (the full library, the current search\'s Songs section, and any album groupings within it)',
......
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