feat(web): add /library/albums wrapping-grid page

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-01 20:26:02 -04:00
parent dae08cd71a
commit 3d0a42865e
2 changed files with 108 additions and 0 deletions
@@ -0,0 +1,55 @@
<script lang="ts">
import { createAlbumsAlphaInfiniteQuery } from '$lib/api/albums';
import AlbumCard from '$lib/components/AlbumCard.svelte';
import AlphabeticalGrid from '$lib/components/AlphabeticalGrid.svelte';
import ApiErrorBanner from '$lib/components/ApiErrorBanner.svelte';
import { useDelayed } from '$lib/utils/useDelayed.svelte';
import type { AlbumRef } from '$lib/api/types';
const queryStore = createAlbumsAlphaInfiniteQuery();
const query = $derived($queryStore);
const albums = $derived(query.data?.pages?.flatMap((p) => p.items) ?? []);
const total = $derived(query.data?.pages?.[0]?.total ?? 0);
const showSkeleton = useDelayed(() => query.isPending);
</script>
<div class="space-y-4">
<header>
<h1 class="font-display text-2xl font-medium text-text-primary">Albums</h1>
{#if !query.isPending && !query.isError}
<p class="text-sm text-text-secondary">
{total} {total === 1 ? 'album' : 'albums'}
</p>
{/if}
</header>
{#if query.isError}
<ApiErrorBanner error={query.error} onRetry={query.refetch} />
{:else if showSkeleton.value && albums.length === 0}
<p class="text-text-secondary">Loading…</p>
{:else if !query.isPending && total === 0}
<p class="text-text-secondary">No albums yet — scan a library folder via the server's config.</p>
{:else}
<AlphabeticalGrid
items={albums}
getKey={(a: AlbumRef) => a.sort_title || a.title}
>
{#snippet item(album: AlbumRef)}
<AlbumCard {album} />
{/snippet}
</AlphabeticalGrid>
{#if query.hasNextPage}
<button
type="button"
class="w-full rounded bg-surface py-2 text-sm hover:bg-surface-hover disabled:opacity-60"
disabled={query.isFetchingNextPage}
onclick={() => query.fetchNextPage()}
>
{query.isFetchingNextPage ? 'Loading…' : 'Load more'}
</button>
{:else if albums.length > 0}
<p class="py-2 text-center text-sm text-text-secondary">End of library</p>
{/if}
{/if}
</div>
@@ -0,0 +1,53 @@
import { describe, expect, test, vi } from 'vitest';
import { render, screen } from '@testing-library/svelte';
import { readable } from 'svelte/store';
vi.mock('$lib/api/albums', () => ({
createAlbumsAlphaInfiniteQuery: () => readable({
data: { pages: [{
items: [
{ id: 'a1', title: 'Apple', sort_title: 'Apple',
artist_id: 'art-1', artist_name: 'X',
track_count: 5, duration_sec: 100, cover_url: '/api/albums/a1/cover' },
{ id: 'b1', title: 'Banana', sort_title: 'Banana',
artist_id: 'art-1', artist_name: 'X',
track_count: 3, duration_sec: 50, cover_url: '/api/albums/b1/cover' }
],
total: 2, limit: 50, offset: 0
}] },
isPending: false,
isError: false,
hasNextPage: false,
isFetchingNextPage: false,
refetch: () => {},
fetchNextPage: () => {}
}),
ALBUM_PAGE_SIZE: 50
}));
vi.mock('$lib/api/client', () => ({ api: { get: vi.fn() } }));
vi.mock('$lib/player/store.svelte', () => ({
enqueueTracks: vi.fn(),
playQueue: vi.fn()
}));
vi.mock('$lib/api/likes', () => ({
createLikedIdsQuery: () => readable({
data: { track_ids: [], album_ids: [], artist_ids: [] },
isPending: false, isError: false
}),
likeEntity: vi.fn(),
unlikeEntity: vi.fn()
}));
import Page from './+page.svelte';
describe('/library/albums', () => {
test('renders title + count + alphabetical dividers', () => {
render(Page);
expect(screen.getByRole('heading', { name: /albums/i })).toBeInTheDocument();
expect(screen.getByText(/2 albums/)).toBeInTheDocument();
expect(screen.getByText('A')).toBeInTheDocument();
expect(screen.getByText('B')).toBeInTheDocument();
expect(screen.getByText('Apple')).toBeInTheDocument();
expect(screen.getByText('Banana')).toBeInTheDocument();
});
});