Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ personal wantlist ("crate").

IT2810 (NTNU) Project 2. Group T19: `erikhfj`, `robertky`, `evenkkl`, `rachelks`.

**Status: M4 delivered – final polish.** See the README's
**Status: Final submission ready (hand-in 27 November).** See the README's
[feature overview](README.md#what-you-can-do-in-crate) for implemented features
and the project status section for planned work.

Expand Down
154 changes: 91 additions & 63 deletions README.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="referrer" content="no-referrer" />
<meta name="description" content="Crate — search, review and collect albums." />
<link rel="icon" type="image/svg+xml" href="%BASE_URL%favicon.svg" />
<title>Crate — album catalog</title>
<script src="%BASE_URL%theme-init.js"></script>
</head>
<body>
<div id="root"></div>
Expand Down
6 changes: 6 additions & 0 deletions client/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
}
})();
81 changes: 58 additions & 23 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 @@ -87,19 +90,27 @@
background: var(--bg);
color: var(--text);
}
.search-section::before,
.search-section__backdrop,
.search-section::after {
content: '';
position: absolute;
inset: 0;
pointer-events: none;
}
.search-section::before {
.search-section__backdrop {
z-index: -2;
background: url('./assets/vinyl-hero.webp') center 22% / cover;
display: block;
overflow: hidden;
}
.search-section__backdrop-image {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
object-position: center 45%;
filter: saturate(0.5) contrast(1.03);
}
.search-section::after {
content: '';
z-index: -1;
background:
linear-gradient(
Expand Down Expand Up @@ -141,13 +152,33 @@
font-size: 1.125rem;
margin: 1.5rem 0 1.875rem;
}
.hero-footer {
margin-top: 2rem;
}
.hero-jump-link {
display: none;
align-items: center;
gap: 0.35rem;
min-height: 2.75rem;
font-size: 0.9rem;
font-weight: 700;
color: var(--accent);
text-decoration: none;
}
.hero-jump-link:hover {
color: var(--accent-hover);
text-decoration: underline;
text-underline-offset: 0.2em;
}
.hero-credit {
margin: 2rem 0 0;
margin: 0;
color: var(--muted);
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 +195,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 All @@ -189,13 +209,13 @@
.search-section {
min-height: 0;
align-items: end;
padding-block: 2.5rem 2rem;
padding-block: 1.5rem 1.25rem;
}
.search-section__content {
padding-inline: 1rem;
}
.search-section::before {
background-position: center 24%;
.search-section__backdrop-image {
object-position: center 40%;
}
.search-section::after {
background: linear-gradient(
Expand All @@ -205,11 +225,26 @@
rgba(5, 12, 8, 0.65)
);
}
.search-section .eyebrow {
margin-bottom: 0.5rem;
}
.search-section h1 {
font-size: clamp(2.5rem, 8vw, 3rem);
font-size: clamp(2rem, 8vw, 2.75rem);
}
.search-section .tagline {
font-size: 1rem;
font-size: 0.95rem;
margin: 0.75rem 0 1rem;
}
.hero-footer {
margin-top: 0.75rem;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 0.5rem 1rem;
}
.hero-jump-link {
display: inline-flex;
}
}
@media (max-width: 420px) {
Expand Down
21 changes: 21 additions & 0 deletions client/src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,27 @@ describe('App search', () => {
within(hero).getByText('Search, rate and collect albums you’ll want to return to.'),
).toBeInTheDocument();
expect(within(hero).getByRole('search')).toBeInTheDocument();
const heroPicture = hero.querySelector('picture.search-section__backdrop');
const heroSource = heroPicture?.querySelector('source');
expect(heroSource).toHaveAttribute('media', '(max-width: 700px)');
expect(heroSource).toHaveAttribute('srcset');
expect(heroSource).not.toHaveAttribute('type');
const heroImage = heroPicture?.querySelector('img');
expect(heroImage).toHaveAttribute('src');
expect(heroImage).toHaveAttribute('aria-hidden', 'true');
expect(heroImage).toHaveAttribute('width', '1280');
expect(heroImage).toHaveAttribute('height', '720');
expect(heroImage).toHaveAttribute('loading', 'eager');
expect(heroImage).toHaveAttribute('fetchpriority', 'high');
expect(heroImage).toHaveAttribute('decoding', 'async');
expect(heroImage).toHaveAttribute('alt', '');
expect(heroImage).not.toHaveAttribute('srcset');
expect(heroImage).not.toHaveAttribute('sizes');
expect(within(hero).queryByRole('img')).not.toBeInTheDocument();
expect(within(hero).getByRole('link', { name: 'Browse catalog' })).toHaveAttribute(
'href',
'#catalogue',
);
expect(document.querySelector('a')).toBe(
screen.getByRole('link', { name: 'Skip to content' }),
);
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
Binary file added client/src/assets/vinyl-hero-mobile.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions client/src/assets/vinyl-hero.LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
- Photo: [Black turntable on brown wooden table](https://unsplash.com/photos/black-turntable-on-brown-wooden-table-TcSckNRL9J8)
- License: [Unsplash License](https://unsplash.com/license), permitting downloading, modification, distribution and use, including commercial use.
- Source: https://images.unsplash.com/photo-1526394931762-90052e97b376
- Local asset: vinyl-hero.webp (1800px wide WebP, quality 80).
- Used as a decorative CSS background with dark overlays. Attribution is also visible in the hero.
- Local assets:
- `vinyl-hero.webp` (1280×720 landscape crop WebP, quality 78)
- `vinyl-hero-mobile.webp` (640×360 landscape crop WebP, quality 75)
- Used as a decorative responsive hero backdrop (`<picture>` / `<img>` with `alt=""` and `aria-hidden="true"`) behind dark overlays. Attribution is also visible in the hero.
Binary file modified client/src/assets/vinyl-hero.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
2 changes: 2 additions & 0 deletions client/src/components/AlbumCover.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ it('uses responsive thumbnails and native loading with decorative semantics', ()
expect(image).toHaveAttribute('loading', 'lazy');
expect(image).not.toHaveAttribute('fetchpriority');
expect(image).toHaveAttribute('decoding', 'async');
expect(image).toHaveAttribute('referrerpolicy', 'no-referrer');
expect(image).toHaveAttribute('alt', '');
expect(screen.queryByRole('img')).not.toBeInTheDocument();
});
Expand All @@ -53,6 +54,7 @@ it('loads detail artwork eagerly with 500px and 1200px thumbnails', () => {
expect(image).toHaveAttribute('loading', 'eager');
expect(image).toHaveAttribute('fetchpriority', 'high');
expect(image).toHaveAttribute('decoding', 'async');
expect(image).toHaveAttribute('referrerpolicy', 'no-referrer');
expect(image).toHaveAttribute('alt', '');
expect(screen.queryByRole('img')).not.toBeInTheDocument();
});
Expand Down
Loading