From c4eaa33e2415d7fdcada9e2ed89de87849756fc5 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Wed, 25 Nov 2026 10:01:35 -0500 Subject: [PATCH] fix(web): a Home row with one or two items no longer stretches them across the page Home rows size their tiles to fill the window, and a row with fewer items than fit split the whole width between them. One suggestion in You might like became an album cover as wide as the page. Tiles now grow to at most twice their minimum width; rows with enough items still fill the window exactly. Co-Authored-By: Claude Opus 5.5 --- web/src/lib/playlists/shelf.test.ts | 10 ++++++++-- web/src/lib/playlists/shelf.ts | 14 +++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/web/src/lib/playlists/shelf.test.ts b/web/src/lib/playlists/shelf.test.ts index 4e668a81..7846b336 100644 --- a/web/src/lib/playlists/shelf.test.ts +++ b/web/src/lib/playlists/shelf.test.ts @@ -6,6 +6,7 @@ import { refreshedLabel, shelfMeta, shelfTileWidth, + MAX_TILE_GROWTH, songsLikeArtist, washTone } from './shelf.js'; @@ -148,9 +149,14 @@ describe('shelfTileWidth', () => { expect(cols * w + (cols - 1) * 16).toBeGreaterThan(1000 - cols); }); - test('a short shelf splits the whole width between its items', () => { - expect(shelfTileWidth(1000, 2, 150, 16)).toBe(492); + test('a short shelf splits the width between its items', () => { expect(shelfTileWidth(400, 2, 150, 16)).toBe(192); + expect(shelfTileWidth(1000, 3, 300, 16)).toBe(322); + }); + + test('a tile on a near-empty shelf stops growing at twice its minimum', () => { + expect(shelfTileWidth(1400, 1, 144, 16)).toBe(144 * MAX_TILE_GROWTH); + expect(shelfTileWidth(1000, 2, 150, 16)).toBe(150 * MAX_TILE_GROWTH); }); test('a narrow window still gets one tile at the min', () => { diff --git a/web/src/lib/playlists/shelf.ts b/web/src/lib/playlists/shelf.ts index 915aa551..0524dcf7 100644 --- a/web/src/lib/playlists/shelf.ts +++ b/web/src/lib/playlists/shelf.ts @@ -123,13 +123,17 @@ function fromHsl(h: number, s: number, l: number): { r: number; g: number; b: nu }; } -// How wide each tile on a shelf is, so the shelf's tiles always fill its -// width: as many columns as fit at `min` pixels, each grown to share the -// width. A shelf with fewer items than that splits the whole width between -// the items it has, so no shelf ends partway across the page. +// How wide each tile on a shelf is, so the shelf's tiles fill its width: as +// many columns as fit at `min` pixels, each grown to share the width. A shelf +// with fewer items than that splits the width between the items it has, but +// no tile grows past MAX_TILE_GROWTH times `min`: a lone album on a wide +// window would otherwise become a cover the size of the page. +export const MAX_TILE_GROWTH = 2; + export function shelfTileWidth(width: number, count: number, min: number, gap: number): number { if (width <= 0) return min; let cols = Math.max(1, Math.floor((width + gap) / (min + gap))); if (count > 0 && count < cols) cols = count; - return Math.max(min, Math.floor((width - (cols - 1) * gap) / cols)); + const shared = Math.floor((width - (cols - 1) * gap) / cols); + return Math.max(min, Math.min(shared, min * MAX_TILE_GROWTH)); }