Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Crate — search, review and collect albums." />
<title>Crate — album catalog</title>
<script src="%BASE_URL%theme-init.js"></script>
</head>
<body>
<div id="root"></div>
Expand Down
10 changes: 10 additions & 0 deletions client/public/theme-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(function () {
try {
var stored = window.localStorage.getItem('crate.theme');
if (stored === 'light' || stored === 'dark') {
document.documentElement.dataset.theme = stored;
}
} catch {
// Ignore storage access errors; CSS media query handles system preference.
}
})();
20 changes: 7 additions & 13 deletions client/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@
gap: 2.5rem;
}
.navigation a {
display: inline-flex;
align-items: center;
min-height: 2.75rem;
padding-block: 0.4rem;
text-decoration: none;
}
.navigation a[aria-current] {
border-bottom: 2px solid var(--header-accent);
padding-block: 0.4rem;
}
.brand {
font-family: var(--font-display);
Expand Down Expand Up @@ -147,7 +150,9 @@
font-size: 0.75rem;
}
.hero-credit a {
display: inline-block;
display: inline-flex;
align-items: center;
min-height: 2.75rem;
padding-block: 0.25rem;
text-underline-offset: 0.2em;
}
Expand All @@ -164,17 +169,6 @@
font-size: 0.8rem;
color: var(--muted);
}
@media (prefers-color-scheme: light) {
.discovery-main .album-card {
background: var(--surface);
border-radius: 3px;
/* An inset border preserves the card and artwork dimensions. */
box-shadow: inset 0 0 0 1px var(--border);
}
.discovery-main .album-card__cover {
background: var(--border);
}
}
@media (max-width: 700px) {
#main {
padding-inline: 1rem;
Expand Down
2 changes: 2 additions & 0 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { lazy, Suspense, useCallback, useEffect, useRef } from 'react';

import Link from './components/Link.js';
import RouteErrorBoundary from './components/RouteErrorBoundary.js';
import ThemeToggle from './components/ThemeToggle.js';
import DiscoveryPage from './pages/DiscoveryPage.js';
import { appHref, stripBasePath, useLocation } from './router.js';

Expand Down Expand Up @@ -85,6 +86,7 @@ export default function App() {
<Link href={crateHref} aria-current={isCrate ? 'page' : undefined}>
Your crate
</Link>
<ThemeToggle />
</nav>
</header>
<RouteErrorBoundary resetKey={pathname}>
Expand Down
26 changes: 26 additions & 0 deletions client/src/components/AlbumCard.css
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@
.album-card:focus-within .album-card__record {
transform: scale(1.025);
}
@media (hover: none), (pointer: coarse) {
.album-card__view {
display: none;
}
}
@media (hover: hover) and (pointer: fine) {
.album-card__view {
opacity: 0;
Expand All @@ -152,6 +157,27 @@
color: var(--accent);
}
}
/* Keep in sync with `@media (prefers-color-scheme: light)` below. */
:root[data-theme='light'] .album-card {
background: var(--surface);
border-radius: 3px;
/* An inset border preserves the card and artwork dimensions. */
box-shadow: inset 0 0 0 1px var(--border);
}
:root[data-theme='light'] .album-card__cover {
background: var(--border);
}
/* Keep in sync with `:root[data-theme='light']` above. */
@media (prefers-color-scheme: light) {
:root:not([data-theme='dark']) .album-card {
background: var(--surface);
border-radius: 3px;
box-shadow: inset 0 0 0 1px var(--border);
}
:root:not([data-theme='dark']) .album-card__cover {
background: var(--border);
}
}
@media (prefers-reduced-motion: reduce) {
.album-card .album-card__record,
.album-card:hover .album-card__record,
Expand Down
8 changes: 5 additions & 3 deletions client/src/components/AlbumCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ it('handles nullable summary fields without inventing a rating or year', () => {
);
expect(screen.getByText('Year unknown')).toBeInTheDocument();
expect(screen.getByText('Not yet rated')).toBeInTheDocument();
expect(screen.getByText('0 reviews')).toBeInTheDocument();
expect(screen.queryByText('0 reviews')).not.toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Abbey Road' })).toHaveAttribute(
'href',
`${import.meta.env.BASE_URL}album/1?q=Abbey&sort=TITLE_ASC`,
Expand Down Expand Up @@ -130,7 +130,7 @@ it.each([false, true])(
const open = vi.fn((event: Event) => event.preventDefault());
link.addEventListener('click', open);
const button = screen.getByRole('button', {
name: saved ? 'In your crate, remove from crate' : 'Add to crate',
name: saved ? `Remove from crate: ${album.title}` : `Add to crate: ${album.title}`,
});
expect(button.closest('a')).toBeNull();
const user = userEvent.setup();
Expand Down Expand Up @@ -165,7 +165,9 @@ it('reports crate mutation errors without navigating', async () => {
<AlbumCard album={album} />
</MockedProvider>,
);
await userEvent.setup().click(screen.getByRole('button', { name: 'Add to crate' }));
await userEvent
.setup()
.click(screen.getByRole('button', { name: `Add to crate: ${album.title}` }));
expect(await screen.findByRole('alert')).toHaveTextContent(
'Could not update your crate',
);
Expand Down
29 changes: 22 additions & 7 deletions client/src/components/AlbumCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ import AlbumCover from './AlbumCover.js';
import CrateButton from './CrateButton.js';
import Link from './Link.js';

export default function AlbumCard({ album }: { album: AlbumSummary }) {
export default function AlbumCard({
album,
onRemovedFromCrate,
}: {
album: AlbumSummary;
onRemovedFromCrate?: () => void;
}) {
const location = useLocation();
const detailHref = appHref(`/album/${album.id}`, location.search);
const rating = album.reviewCount > 0 ? album.averageRating : null;
const displayTitle = album.title || 'Untitled album';

return (
<article className="album-card" aria-labelledby={`album-${album.id}`}>
Expand Down Expand Up @@ -53,16 +60,18 @@ export default function AlbumCard({ album }: { album: AlbumSummary }) {
</div>
<h3 id={`album-${album.id}`}>
<Link className="album-card__link" href={detailHref}>
{album.title || 'Untitled album'}
{displayTitle}
</Link>
</h3>
<p className="artist">
{album.artists.map((artist) => artist.name).join(', ') || 'Artist unknown'}
</p>
<p className="album-card__reviews">
{album.reviewCount.toLocaleString('en-US')}{' '}
{album.reviewCount === 1 ? 'review' : 'reviews'}
</p>
{album.reviewCount > 0 && (
<p className="album-card__reviews">
{album.reviewCount.toLocaleString('en-US')}{' '}
{album.reviewCount === 1 ? 'review' : 'reviews'}
</p>
)}
<div className="album-card__footer">
{album.genres.length > 0 ? (
<ul className="genre-tags" aria-label="Genres">
Expand All @@ -73,7 +82,13 @@ export default function AlbumCard({ album }: { album: AlbumSummary }) {
) : (
<p className="album-card__genres-empty">Genre unknown</p>
)}
<CrateButton albumId={album.id} isInCrate={album.isInCrate} compact />
<CrateButton
albumId={album.id}
albumTitle={displayTitle}
isInCrate={album.isInCrate}
compact
onRemoved={onRemovedFromCrate}
/>
</div>
</div>
</article>
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/AlbumCover.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
inset: 0;
width: 100%;
height: 100%;
object-fit: contain;
object-fit: cover;
background: var(--surface-raised);
}
.album-card__record {
Expand Down
Loading