diff --git a/web/index.html b/web/index.html index 7c6ab11..e14eb20 100644 --- a/web/index.html +++ b/web/index.html @@ -5,7 +5,7 @@ - + diff --git a/web/package-lock.json b/web/package-lock.json index 38a2c84..5d9eb13 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -1,16 +1,15 @@ { - "name": "web", + "name": "sonda-web", "version": "0.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "web", + "name": "sonda-web", "version": "0.0.0", "dependencies": { "@base-ui/react": "^1.9.0", "@fontsource/figtree": "^5.3.0", - "@fontsource/fraunces": "^5.3.0", "@tanstack/react-query": "^5.107.1", "class-variance-authority": "^0.7.1", "cn": "^0.5.2", @@ -821,15 +820,6 @@ "url": "https://github.com/sponsors/ayuhito" } }, - "node_modules/@fontsource/fraunces": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/@fontsource/fraunces/-/fraunces-5.3.0.tgz", - "integrity": "sha512-LEHTOBiZufQzAvnAe2rZ8ZknbDS28Q9kzwb0L+gZJEmjLGr8hhZ/5NuHXwDuHBWhVXYoiGGXmrb0H6Ko/RrHTg==", - "license": "OFL-1.1", - "funding": { - "url": "https://github.com/sponsors/ayuhito" - } - }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.13", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", diff --git a/web/package.json b/web/package.json index 5fc1577..b8762b1 100644 --- a/web/package.json +++ b/web/package.json @@ -14,7 +14,6 @@ "dependencies": { "@base-ui/react": "^1.9.0", "@fontsource/figtree": "^5.3.0", - "@fontsource/fraunces": "^5.3.0", "@tanstack/react-query": "^5.107.1", "class-variance-authority": "^0.7.1", "cn": "^0.5.2", diff --git a/web/src/components/Cover.test.tsx b/web/src/components/Cover.test.tsx index 9c90a63..7b610e0 100644 --- a/web/src/components/Cover.test.tsx +++ b/web/src/components/Cover.test.tsx @@ -86,3 +86,33 @@ test('the cover of a friend’s album comes through this server, from the friend const { container } = render() expect(container.querySelector('img')!.getAttribute('src')).toBe('/api/v1/friends/3/albums/12/cover') }) + +test('with no cover the rings of Sonda stand in, on a colour taken from the album', () => { + const { container } = render() + const ph = placeholder(container)! + expect(ph).not.toBeNull() + expect(ph.querySelectorAll('[data-ring]')).toHaveLength(3) + expect(container.firstElementChild).toHaveAttribute('data-tone') +}) + +test('an album keeps its colour, and albums do not all have the same one', () => { + const tone = (id: number, friend?: number) => { + const { container, unmount } = render() + fireEvent.error(container.querySelector('img')!) + const t = container.firstElementChild!.getAttribute('data-tone') + unmount() + return t + } + expect(tone(12)).toBe(tone(12)) + expect(new Set([1, 2, 3, 4, 5, 6, 7, 8].map((id) => tone(id))).size).toBe(8) + // A friend's album 12 is not this server's album 12. + expect(tone(12, 3)).not.toBe(tone(12)) +}) + +test('a cover that cannot be loaded falls back to the rings, and the picture hides them when it loads', () => { + const { container } = render() + expect(placeholder(container)).toBeNull() + fireEvent.error(container.querySelector('img')!) + expect(placeholder(container)).not.toBeNull() + expect(container.querySelector('img')).toBeNull() +}) diff --git a/web/src/components/Cover.tsx b/web/src/components/Cover.tsx index d96db99..4ce80f9 100644 --- a/web/src/components/Cover.tsx +++ b/web/src/components/Cover.tsx @@ -11,33 +11,57 @@ interface CoverProps { fluid?: boolean } -/** The cover of an album, or concentric rings when there is none (or it cannot be loaded). */ +/** + * The colours an album with no cover gets: a ground and the colour of the rings on it. They are the same for an + * album every time, so a list of albums is told apart at a glance, and none of them is the colour of a friend. + */ +const TONES = [ + { bg: '#1e6f72', ring: '#8fe9e3' }, + { bg: '#b9503b', ring: '#f6c0b2' }, + { bg: '#3a4e8c', ring: '#b7c6f2' }, + { bg: '#5e3b73', ring: '#d9b8ec' }, + { bg: '#2f7a4e', ring: '#b5e8c8' }, + { bg: '#8c3a5a', ring: '#f0b7cb' }, + { bg: '#2d5f9a', ring: '#b3d2f5' }, + { bg: '#496b7a', ring: '#c6dce5' }, +] as const + +/** The three rings of Sonda, in the colour of the tone: the stand-in for a cover that is missing. */ +const RINGS = [ + { size: '20%', opacity: 1 }, + { size: '44%', opacity: 0.6 }, + { size: '68%', opacity: 0.3 }, +] as const + +/** The cover of an album, or the rings of Sonda when there is none (or it cannot be loaded). */ export default function Cover({ albumId, friend, size, fluid = false }: CoverProps) { useAccessToken() // the URL carries the token, so it has to follow a renewal const src = albumId === null ? null : mediaUrl(coverPath(friend, albumId)) // A failure is remembered for this URL only: a renewed token makes a new URL, which is tried again. const [failed, setFailed] = useState(null) const showImage = src !== null && failed !== src + const tone = (((albumId ?? 0) + (friend ?? 0) * 3) % TONES.length + TONES.length) % TONES.length + const { bg, ring } = TONES[tone] return (
{showImage ? ( - setFailed(src)} - /> + setFailed(src)} /> ) : ( - + )}
) diff --git a/web/src/components/layout/NowPlaying.tsx b/web/src/components/layout/NowPlaying.tsx index 6b91025..8d9b0ca 100644 --- a/web/src/components/layout/NowPlaying.tsx +++ b/web/src/components/layout/NowPlaying.tsx @@ -71,7 +71,7 @@ export default function NowPlaying() {
- + {track.title}

diff --git a/web/src/components/layout/PlayerBar.tsx b/web/src/components/layout/PlayerBar.tsx index d4926fe..57fa1ee 100644 --- a/web/src/components/layout/PlayerBar.tsx +++ b/web/src/components/layout/PlayerBar.tsx @@ -55,7 +55,7 @@ export default function PlayerBar() { return (