Skip to content
Merged
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,14 @@ committing it. MusicBrainz core data is CC0 1.0; genre associations are
user-contributed tag data under CC BY-NC-SA 3.0. The snapshot retains that
distinction and the MusicBrainz release-group IDs for attribution and
reproducibility. See [MusicBrainz Data License](https://musicbrainz.org/doc/About/Data_License)
and [MusicBrainz API](https://musicbrainz.org/doc/MusicBrainz_API). Album covers
remain out of scope for this issue.
and [MusicBrainz API](https://musicbrainz.org/doc/MusicBrainz_API).

Album artwork is loaded externally from Cover Art Archive using the existing
MusicBrainz release-group IDs, rather than bundled into the application. Cover
availability is optional; albums without an ID or available artwork use the
existing vinyl placeholder. The artwork attribution on the album detail page
links to the corresponding MusicBrainz release-group page. Artwork rights remain
with their respective rights holders.

### Scalability

Expand Down Expand Up @@ -241,9 +247,9 @@ We consider sustainability through design choices that reduce unnecessary data t
| `AlbumDetailPage-*.css` | 1.94 kB | 0.71 kB |
| `index.html` | 0.51 kB | 0.31 kB |

The two `AlbumDetailPage` rows represent the separate chunks for the album detail route and are not part of the search page payload. Opening an album uses normal page navigation, while previously downloaded assets may be reused by the browser.
The two `AlbumDetailPage` rows represent the separate chunks for the album detail route and are not part of the search page payload. Opening an album uses normal page navigation, while previously downloaded assets may be reused by the browser. Artwork is fetched separately from Cover Art Archive and is not included in these bundle sizes. Browser-native responsive images (`srcSet`/`sizes`) let the browser select an appropriate image size; card images load lazily, while detail artwork loads eagerly.

**Requests for a typical search:** An uncached search initially fetches up to 20 albums in one `searchAlbums` request. Infinite scroll loads up to two additional pages automatically, while further pages are loaded using the Load more button. Previously fetched pages are reused from Apollo's cache without new requests. No search requests are sent while the user types.
**Requests for a typical search:** An uncached search initially fetches up to 20 albums in one `searchAlbums` request. Infinite scroll loads up to two additional pages automatically, while further pages are loaded using the Load more button. Previously fetched pages are reused from Apollo's cache without new GraphQL requests. No search requests are sent while the user types. Album artwork adds separate external image requests as cards approach the viewport.

## Project status

Expand Down Expand Up @@ -271,6 +277,8 @@ The two `AlbumDetailPage` rows represent the separate chunks for the album detai

**Album details and reviews:** Album pages display tracks, average ratings and reviews. Users can write, edit and delete their own reviews.

**Album artwork:** Discover, My Crate and AlbumDetailPage display Cover Art Archive images when available, with the vinyl placeholder as a fallback.

**Personal crate:** Users can add or remove albums from their crate on both search results and album detail pages, and a crate page lists everything they have saved, newest first, with paging. The API returns only the requesting user's items. User identity is simulated using a locally stored ID rather than a login system.

**Planned for M4:** Playwright end-to-end tests, and browsing albums without entering a search term.
Expand Down
1 change: 1 addition & 0 deletions client/src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const album: AlbumSummary = {
title: 'Abbey Road',
artists: [{ id: '1', name: 'The Beatles' }],
releaseYear: 1969,
musicBrainzReleaseGroupId: null,
genres: [{ id: '1', name: 'Rock' }],
averageRating: 4.8,
reviewCount: 1240,
Expand Down
1 change: 1 addition & 0 deletions client/src/a11y.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const album: AlbumSummary = {
title: 'Abbey Road',
artists: [{ id: '1', name: 'The Beatles' }],
releaseYear: 1969,
musicBrainzReleaseGroupId: null,
genres: [{ id: '1', name: 'Rock' }],
averageRating: 4.8,
reviewCount: 1240,
Expand Down
1 change: 1 addition & 0 deletions client/src/api/albumDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const ALBUM_DETAIL = graphql(`
id
title
releaseYear
musicBrainzReleaseGroupId
artists {
id
name
Expand Down
1 change: 1 addition & 0 deletions client/src/api/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function result(ids: string[], endCursor: string, hasNextPage = true): SearchAlb
artists: [],
genres: [],
releaseYear: null,
musicBrainzReleaseGroupId: null,
averageRating: null,
reviewCount: 0,
isInCrate: false,
Expand Down
1 change: 1 addition & 0 deletions client/src/api/crate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const MY_CRATE = graphql(`
id
title
releaseYear
musicBrainzReleaseGroupId
averageRating
reviewCount
isInCrate
Expand Down
1 change: 1 addition & 0 deletions client/src/api/searchAlbums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const SEARCH_ALBUMS = graphql(`
id
title
releaseYear
musicBrainzReleaseGroupId
artists {
id
name
Expand Down
29 changes: 8 additions & 21 deletions client/src/components/AlbumCard.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import './AlbumCover.css';

.album-card {
position: relative;
isolation: isolate;
Expand All @@ -17,27 +19,12 @@
display: grid;
place-items: center;
}
.album-card__record {
width: 68%;
aspect-ratio: 1;
border-radius: 50%;
border: 1px solid var(--border-strong);
background: repeating-radial-gradient(
circle,
var(--surface) 0 5px,
var(--border) 6px 7px
);
display: grid;
place-items: center;
transition: transform 400ms ease;
}
.album-card__record::after {
content: '';
width: 25%;
aspect-ratio: 1;
border-radius: 50%;
border: 1px solid var(--border-strong);
background: var(--surface-raised);
/* Two 18rem columns plus the 1.375rem gap no longer fit below this width. */
@container album-grid (width < 37.375rem) {
.album-card {
max-width: 26rem;
margin-inline: auto;
}
}
.album-card__view {
position: absolute;
Expand Down
26 changes: 25 additions & 1 deletion client/src/components/AlbumCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const album: AlbumSummary = {
artists: [],
genres: [],
releaseYear: null,
musicBrainzReleaseGroupId: null,
averageRating: null,
reviewCount: 0,
isInCrate: false,
Expand All @@ -28,6 +29,7 @@ it('handles nullable summary fields without inventing a rating or year', () => {
artists: [{ id: '1', name: 'The Beatles' }],
genres: [{ id: '1', name: 'Rock' }],
releaseYear: null,
musicBrainzReleaseGroupId: null,
averageRating: null,
reviewCount: 0,
isInCrate: false,
Expand Down Expand Up @@ -69,6 +71,22 @@ it('shows a real aggregate rating and review count', () => {
expect(screen.getByText('Average rating:')).toBeInTheDocument();
});

it('renders the album cover beneath the existing View album overlay', () => {
const releaseGroupId = '004bf1bb-df91-4724-8292-6c50b73216b8';
const { container } = render(
<MockedProvider>
<AlbumCard album={{ ...album, musicBrainzReleaseGroupId: releaseGroupId }} />
</MockedProvider>,
);
const cover = container.querySelector('.album-card__cover');
expect(cover?.querySelector('img')).toHaveAttribute(
'src',
`https://coverartarchive.org/release-group/${releaseGroupId}/front-250`,
);
expect(cover).toContainElement(screen.getByText('View album'));
expect(screen.getByRole('link', { name: album.title })).toBeInTheDocument();
});

it.each([false, true])(
'keeps keyboard navigation and the crate mutation separate (saved: %s)',
async (saved) => {
Expand Down Expand Up @@ -99,7 +117,13 @@ it.each([false, true])(
},
]}
>
<AlbumCard album={{ ...album, isInCrate: saved }} />
<AlbumCard
album={{
...album,
isInCrate: saved,
musicBrainzReleaseGroupId: '004bf1bb-df91-4724-8292-6c50b73216b8',
}}
/>
</MockedProvider>,
);
const link = screen.getByRole('link', { name: album.title });
Expand Down
6 changes: 5 additions & 1 deletion client/src/components/AlbumCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import './AlbumCard.css';

import type { AlbumSummary } from '../api/searchAlbums.js';
import CrateButton from './CrateButton.js';
import AlbumCover from './AlbumCover.js';

export default function AlbumCard({ album }: { album: AlbumSummary }) {
const detailHref = `${import.meta.env.BASE_URL}album/${album.id}${window.location.search}`;
Expand All @@ -10,7 +11,10 @@ export default function AlbumCard({ album }: { album: AlbumSummary }) {
return (
<article className="album-card" aria-labelledby={`album-${album.id}`}>
<div className="album-card__cover" aria-hidden="true">
<span className="album-card__record" />
<AlbumCover
musicBrainzReleaseGroupId={album.musicBrainzReleaseGroupId}
sizes="auto, (max-width: 38rem) min(26rem, calc(100vw - 2rem)), (max-width: 60rem) 50vw, 25rem"
/>
<span className="album-card__view">
View album <span>↗</span>
</span>
Expand Down
39 changes: 39 additions & 0 deletions client/src/components/AlbumCover.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.album-cover {
position: relative;
width: 100%;
aspect-ratio: 1;
display: grid;
place-items: center;
overflow: hidden;
background: var(--surface-raised);
}
.album-cover__image {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
object-fit: contain;
background: var(--surface-raised);
}
.album-card__record {
width: 68%;
aspect-ratio: 1;
border-radius: 50%;
border: 1px solid var(--border-strong);
background: repeating-radial-gradient(
circle,
var(--surface) 0 5px,
var(--border) 6px 7px
);
display: grid;
place-items: center;
transition: transform 400ms ease;
}
.album-card__record::after {
content: '';
width: 25%;
aspect-ratio: 1;
border-radius: 50%;
border: 1px solid var(--border-strong);
background: var(--surface-raised);
}
94 changes: 94 additions & 0 deletions client/src/components/AlbumCover.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { fireEvent, render, screen } from '@testing-library/react';
import { expect, it } from 'vitest';

import AlbumCover from './AlbumCover.js';

const releaseGroupId = '004bf1bb-df91-4724-8292-6c50b73216b8';
const coverUrl = `https://coverartarchive.org/release-group/${releaseGroupId}/front`;
const sizes = '(max-width: 38rem) calc(100vw - 2rem), 25rem';

it.each(['card', 'detail'] as const)(
'renders only the decorative vinyl placeholder when the ID is missing (%s)',
(variant) => {
const { container } = render(
<AlbumCover musicBrainzReleaseGroupId={null} sizes={sizes} variant={variant} />,
);
expect(container.querySelector('img')).toBeNull();
expect(container.querySelector('.album-card__record')).toBeInTheDocument();
expect(container.firstChild).toHaveAttribute('aria-hidden', 'true');
},
);

it('uses responsive thumbnails and native loading with decorative semantics', () => {
const { container } = render(
<AlbumCover musicBrainzReleaseGroupId={releaseGroupId} sizes={sizes} />,
);
const image = container.querySelector('img');
expect(image).toHaveAttribute('src', `${coverUrl}-250`);
expect(image).toHaveAttribute('srcset', `${coverUrl}-250 250w, ${coverUrl}-500 500w`);
expect(image).toHaveAttribute('sizes', sizes);
expect(image).toHaveAttribute('width', '500');
expect(image).toHaveAttribute('height', '500');
expect(image).toHaveAttribute('loading', 'lazy');
expect(image).toHaveAttribute('decoding', 'async');
expect(image).toHaveAttribute('alt', '');
expect(screen.queryByRole('img')).not.toBeInTheDocument();
});

it('loads detail artwork eagerly with 500px and 1200px thumbnails', () => {
const { container } = render(
<AlbumCover
musicBrainzReleaseGroupId={releaseGroupId}
sizes="26rem"
variant="detail"
/>,
);
const image = container.querySelector('img');
expect(image).toHaveAttribute('src', `${coverUrl}-500`);
expect(image).toHaveAttribute('srcset', `${coverUrl}-500 500w, ${coverUrl}-1200 1200w`);
expect(image).toHaveAttribute('sizes', '26rem');
expect(image).toHaveAttribute('width', '1200');
expect(image).toHaveAttribute('height', '1200');
expect(image).toHaveAttribute('loading', 'eager');
expect(image).toHaveAttribute('decoding', 'async');
expect(image).toHaveAttribute('alt', '');
expect(screen.queryByRole('img')).not.toBeInTheDocument();
});

it.each(['card', 'detail'] as const)(
'keeps the fallback after failure and allows a different album to load (%s)',
(variant) => {
const { container, rerender } = render(
<AlbumCover
musicBrainzReleaseGroupId={releaseGroupId}
sizes={sizes}
variant={variant}
/>,
);
fireEvent.error(container.querySelector('img')!);
expect(container.querySelector('img')).toBeNull();
expect(container.querySelector('.album-card__record')).toBeInTheDocument();

rerender(
<AlbumCover
musicBrainzReleaseGroupId={releaseGroupId}
sizes={sizes}
variant={variant}
/>,
);
expect(container.querySelector('img')).toBeNull();

const anotherId = '0106c398-837d-3300-9a3c-29ba1eb0abd1';
rerender(
<AlbumCover
musicBrainzReleaseGroupId={anotherId}
sizes={sizes}
variant={variant}
/>,
);
expect(container.querySelector('img')).toHaveAttribute(
'src',
`https://coverartarchive.org/release-group/${anotherId}/front-${variant === 'detail' ? 500 : 250}`,
);
},
);
48 changes: 48 additions & 0 deletions client/src/components/AlbumCover.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import './AlbumCover.css';

import { useState } from 'react';

type AlbumCoverProps = {
musicBrainzReleaseGroupId: string | null;
sizes: string;
variant?: 'card' | 'detail';
onLoadChange?: (loaded: boolean) => void;
};

export default function AlbumCover({
musicBrainzReleaseGroupId,
sizes,
variant = 'card',
onLoadChange,
}: AlbumCoverProps) {
const [failedId, setFailedId] = useState<string | null>(null);
const smallSize = variant === 'detail' ? 500 : 250;
const largeSize = variant === 'detail' ? 1200 : 500;
const coverUrl = musicBrainzReleaseGroupId
? `https://coverartarchive.org/release-group/${musicBrainzReleaseGroupId}/front`
: null;

return (
<div className="album-cover" aria-hidden="true">
<span className="album-card__record" />
{coverUrl && failedId !== musicBrainzReleaseGroupId && (
<img
className="album-cover__image"
src={`${coverUrl}-${smallSize}`}
srcSet={`${coverUrl}-${smallSize} ${smallSize}w, ${coverUrl}-${largeSize} ${largeSize}w`}
sizes={sizes}
width={largeSize}
height={largeSize}
loading={variant === 'detail' ? 'eager' : 'lazy'}
decoding="async"
alt=""
onLoad={() => onLoadChange?.(true)}
onError={() => {
setFailedId(musicBrainzReleaseGroupId);
onLoadChange?.(false);
}}
/>
)}
</div>
);
}
1 change: 1 addition & 0 deletions client/src/components/ResultsLayout.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
}

.album-grid {
container: album-grid / inline-size;
list-style: none;
margin: 0;
padding: 0;
Expand Down
Loading