feat(web): home shelves you can tell apart at a glance
release / go (push) Successful in 1m46s
release / web (push) Failing after 1m8s
release / govulncheck (push) Successful in 23s
release / integration (push) Successful in 4m12s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 1m38s
release / android (push) Canceled after 3m3s

Each home shelf now has its own shape. Main mixes and playlists are wide
cards: the lead album's cover on a wash of its own colour, with the name
and what the mix is built from beside it rather than over the art. Songs
like mixes are circles, the shape artists already have. Genre mixes are
short bands with a fan of three covers. Shelf sizes step down from the
main mixes.

Tiles show album covers in place of the four-cover collage, and no cover
repeats along a shelf while a tile still has an unused one. The size and
refresh time every mix on a shelf shares is said once, beside the shelf's
title. Library pages keep the square card.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 16:09:02 -05:00
co-authored by Claude Opus 5.5
parent ec017838a2
commit 5e7b8a7694
9 changed files with 512 additions and 51 deletions
+98
View File
@@ -0,0 +1,98 @@
import { describe, expect, test } from 'vitest';
import type { Playlist } from '#lib/api/types.js';
import { assignShelfCovers, refreshedLabel, shelfMeta, songsLikeArtist } from './shelf.js';
function pl(over: Partial<Playlist>): Playlist {
return {
id: 'p',
user_id: 'u',
owner_username: 'me',
name: 'Mix',
description: '',
is_public: false,
kind: 'system',
system_variant: 'for_you',
refreshable: true,
seed_artist_id: null,
cover_url: '',
track_count: 100,
duration_sec: 0,
created_at: '2026-11-23T08:00:00Z',
updated_at: '2026-11-23T08:00:00Z',
...over
};
}
describe('assignShelfCovers', () => {
test('each tile takes the first album no earlier tile shows', () => {
const got = assignShelfCovers(
[
pl({ cover_album_ids: ['a', 'b', 'c'] }),
pl({ cover_album_ids: ['a', 'd'] }),
pl({ cover_album_ids: ['a', 'd', 'e'] })
],
1
);
expect(got).toEqual([['a'], ['d'], ['e']]);
});
test('a band takes three unused albums', () => {
const got = assignShelfCovers(
[pl({ cover_album_ids: ['a', 'b', 'c', 'd'] }), pl({ cover_album_ids: ['b', 'c', 'e', 'f', 'g'] })],
3
);
expect(got).toEqual([['a', 'b', 'c'], ['e', 'f', 'g']]);
});
test('a tile whose albums are all taken reuses its own rather than showing nothing', () => {
const got = assignShelfCovers([pl({ cover_album_ids: ['a'] }), pl({ cover_album_ids: ['a'] })], 1);
expect(got).toEqual([['a'], ['a']]);
});
test('a playlist with no cover albums gets none', () => {
expect(assignShelfCovers([pl({})], 1)).toEqual([[]]);
});
});
describe('shelfMeta', () => {
const now = new Date('2026-11-23T15:00:00Z');
test('equal sizes and the same refresh read as one line', () => {
const mixes = [pl({ track_count: 25 }), pl({ track_count: 25 })];
expect(shelfMeta(mixes, now)).toBe('25 songs each · refreshed today');
});
test('sizes within a tenth of each other read as "about"', () => {
const mixes = [95, 97, 99, 100].map((n) => pl({ track_count: n }));
expect(shelfMeta(mixes, now)).toBe('About 100 songs each · refreshed today');
});
test('sizes that differ widely are left to the tiles', () => {
const mixes = [pl({ track_count: 20 }), pl({ track_count: 100 })];
expect(shelfMeta(mixes, now)).toBe('Refreshed today');
});
test('user playlists do not count, and a shelf of only them says nothing', () => {
const mine = pl({ kind: 'user', system_variant: null, track_count: 3, created_at: '2025-01-01T00:00:00Z' });
expect(shelfMeta([mine], now)).toBe('');
expect(shelfMeta([pl({ track_count: 50 }), mine], now)).toBe('50 songs each · refreshed today');
});
test('different refresh days are not summarised', () => {
const mixes = [pl({}), pl({ created_at: '2026-11-20T08:00:00Z' })];
expect(shelfMeta(mixes, now)).toBe('100 songs each');
});
});
describe('refreshedLabel', () => {
test('yesterday and older', () => {
const now = new Date('2026-11-23T12:00:00');
expect(refreshedLabel('2026-11-22T12:00:00', now)).toBe('Refreshed yesterday');
expect(refreshedLabel('2026-11-20T12:00:00', now)).toBe('Refreshed 4 days ago');
});
});
test('songsLikeArtist drops the shelf-wide prefix', () => {
expect(songsLikeArtist(pl({ name: 'Songs like Low Tide Choir' }))).toBe('Low Tide Choir');
expect(songsLikeArtist(pl({ name: 'Something else' }))).toBe('Something else');
});
+72
View File
@@ -0,0 +1,72 @@
// What a home shelf of playlist tiles shows: which album covers each tile
// gets, and the one line of facts the shelf's tiles share.
import type { Playlist } from '#lib/api/types.js';
// Each tile takes the first of its playlist's cover albums that no tile
// before it on the shelf already shows, so a shelf never repeats a cover
// while a tile still has an unused one. A tile whose albums are all taken
// reuses its own first albums rather than showing nothing. `perTile` is
// how many covers a tile shows (one for a card, three for a genre band).
export function assignShelfCovers(playlists: Playlist[], perTile: number): string[][] {
const used = new Set<string>();
return playlists.map((p) => {
const own = p.cover_album_ids ?? [];
const fresh = own.filter((id) => !used.has(id)).slice(0, perTile);
const picked = fresh.length > 0 ? fresh : own.slice(0, perTile);
for (const id of picked) used.add(id);
return picked;
});
}
// System playlists are rebuilt in place, so created_at is when the mix was
// last refreshed. Worded for a person, not as "3h ago".
export function refreshedLabel(iso: string, now: Date = new Date()): string {
const t = new Date(iso);
if (Number.isNaN(t.getTime())) return '';
const mins = Math.floor((now.getTime() - t.getTime()) / 60000);
if (mins < 5) return 'Refreshed just now';
const startOfToday = new Date(now);
startOfToday.setHours(0, 0, 0, 0);
if (t.getTime() >= startOfToday.getTime()) return 'Refreshed today';
const days = Math.floor((startOfToday.getTime() - t.getTime()) / 86400000) + 1;
if (days <= 1) return 'Refreshed yesterday';
if (days < 7) return `Refreshed ${days} days ago`;
return `Refreshed ${t.toLocaleDateString(undefined, { month: 'short', day: 'numeric' })}`;
}
// The facts every system mix on a shelf has in common, said once beside the
// shelf's title instead of under each tile: their size when it is about the
// same, and when they were refreshed when that is the same. Empty when the
// mixes share nothing worth saying. User playlists are left out: their sizes
// and ages are their own.
export function shelfMeta(playlists: Playlist[], now: Date = new Date()): string {
const mixes = playlists.filter((p) => p.kind === 'system');
if (mixes.length === 0) return '';
const parts: string[] = [];
const counts = mixes.map((p) => p.track_count).sort((a, b) => a - b);
const lo = counts[0];
const hi = counts[counts.length - 1];
if (lo === hi) {
parts.push(`${lo} ${lo === 1 ? 'song' : 'songs'} each`);
} else if (hi - lo <= hi * 0.1) {
// Close enough to read as one size: round the middle to a friendly 5.
const mid = counts[Math.floor(counts.length / 2)];
parts.push(`about ${Math.max(5, Math.round(mid / 5) * 5)} songs each`);
}
const labels = new Set(mixes.map((p) => refreshedLabel(p.created_at, now)));
if (labels.size === 1) {
const [label] = labels;
if (label) parts.push(label.toLowerCase());
}
const line = parts.join(' · ');
return line.charAt(0).toUpperCase() + line.slice(1);
}
// "Songs like Low Tide Choir" → "Low Tide Choir": a Songs like tile labels
// the artist under its circle, so the prefix would only repeat the shelf.
export function songsLikeArtist(p: Playlist): string {
return p.name.replace(/^Songs like\s+/i, '');
}