diff --git a/web/src/components/Cover.tsx b/web/src/components/Cover.tsx index 4ce80f9..1ce7bca 100644 --- a/web/src/components/Cover.tsx +++ b/web/src/components/Cover.tsx @@ -1,6 +1,7 @@ import { useState } from 'react' import { mediaUrl, useAccessToken } from '@/auth/session' import { coverPath } from '@/player/media' +import { TONES } from './tones' interface CoverProps { albumId: number | null @@ -11,21 +12,6 @@ interface CoverProps { fluid?: boolean } -/** - * 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 }, diff --git a/web/src/components/tones.ts b/web/src/components/tones.ts new file mode 100644 index 0000000..a363bd7 --- /dev/null +++ b/web/src/components/tones.ts @@ -0,0 +1,21 @@ +/** + * 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. + */ +export 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 + +/** A tone for a name, always the same one: the colour of a mix. */ +export function toneOfText(text: string): number { + let sum = 0 + for (const ch of text) sum = (sum * 31 + ch.codePointAt(0)!) >>> 0 + return sum % TONES.length +} diff --git a/web/src/i18n/locales/en.json b/web/src/i18n/locales/en.json index 84e57ba..2a33507 100644 --- a/web/src/i18n/locales/en.json +++ b/web/src/i18n/locales/en.json @@ -715,6 +715,8 @@ "mixes": { "forYou": "Made for you", "byGenre": "By genre", + "fromListening": "From your listening", + "fromGenres": "From the genres of your files", "empty": "No mixes yet. They appear when your library has songs with a genre, or songs you have not heard.", "kind": { "favourites": "Your favourites", diff --git a/web/src/i18n/locales/it.json b/web/src/i18n/locales/it.json index 5a85df9..73100f9 100644 --- a/web/src/i18n/locales/it.json +++ b/web/src/i18n/locales/it.json @@ -715,6 +715,8 @@ "mixes": { "forYou": "Fatti per te", "byGenre": "Per genere", + "fromListening": "Dal tuo ascolto", + "fromGenres": "Dai generi dei tuoi file", "empty": "Ancora nessun mix. Compaiono quando la libreria ha brani con un genere, o brani che non hai ancora ascoltato.", "kind": { "favourites": "I tuoi preferiti", diff --git a/web/src/pages/MixesPage.tsx b/web/src/pages/MixesPage.tsx index e37d1a9..5ace2e1 100644 --- a/web/src/pages/MixesPage.tsx +++ b/web/src/pages/MixesPage.tsx @@ -1,22 +1,27 @@ import { useTranslation } from 'react-i18next' import { Link } from 'react-router-dom' import { useMixes, type Mix } from '@/api/mixes' -import { CARD_GRID } from '@/components/cards' -import MixCover from '@/components/MixCover' +import { TONES, toneOfText } from '@/components/tones' import Section from '@/components/Section' import { EmptyMessage, ErrorMessage, Loading } from '@/components/Status' import { mixTitle } from './mixTitle' import PageTitle from '@/components/PageTitle' +/** Tiles are wide, a few in a row: the name needs room. */ +const TILES = 'grid grid-cols-[repeat(auto-fit,minmax(min(250px,100%),1fr))] gap-4' + function MixCard({ mix }: { mix: Mix }) { const { t } = useTranslation() + const tone = toneOfText(mix.id) return ( - - - - {mixTitle(t, mix)} - {mix.artists.join(', ')} - + + {mixTitle(t, mix)} + {t(mix.kind === 'genre' ? 'mixes.fromGenres' : 'mixes.fromListening')} ) } @@ -41,12 +46,12 @@ export default function MixesPage() { <> {forYou.length > 0 && (
-
{forYou.map((m) => )}
+
{forYou.map((m) => )}
)} {genres.length > 0 && (
-
{genres.map((m) => )}
+
{genres.map((m) => )}
)} diff --git a/web/src/pages/mixes.test.tsx b/web/src/pages/mixes.test.tsx index e309956..e743dae 100644 --- a/web/src/pages/mixes.test.tsx +++ b/web/src/pages/mixes.test.tsx @@ -76,12 +76,12 @@ test('the mixes page shows the mixes made from my listening first, then one for const forYou = await screen.findByRole('region', { name: 'Made for you' }) const names = within(forYou).getAllByRole('link').map((l) => l.textContent) expect(names).toEqual([expect.stringContaining('Your favourites'), expect.stringContaining('Rediscover'), expect.stringContaining('New to you')]) - expect(within(forYou).getByRole('link', { name: /Your favourites/ })).toHaveTextContent('Radiohead, Muse') + expect(within(forYou).getByRole('link', { name: /Your favourites/ })).toHaveTextContent('From your listening') const genres = screen.getByRole('region', { name: 'By genre' }) const rock = within(genres).getByRole('link', { name: /Hard Rock Mix/ }) expect(rock).toHaveAttribute('href', `/mixes/${HARD_ROCK}`) - expect(rock).toHaveTextContent('Scorpions, AC/DC, Kiss') + expect(rock).toHaveTextContent('From the genres of your files') expect(within(genres).getByRole('link', { name: /Synthwave Mix/ })).toBeInTheDocument() }) @@ -223,26 +223,21 @@ test('the mixes made from listening have their own names', async () => { const coversOf = (el: HTMLElement) => Array.from(el.querySelectorAll('img')).map((img) => img.getAttribute('src')) -test('a mix with four albums with a cover shows them as a collage on its card', async () => { - mockFetch({ 'GET /api/v1/mixes': () => ({ items: [mix('genre:rock', 'genre', 'rock', ['Queen'], [11, 12, 13, 14, 15])] }) }) +test('a mix is a tile of colour with its name big, not a picture', async () => { + mockFetch({ 'GET /api/v1/mixes': () => ({ items: [mix('genre:rock', 'genre', 'rock', ['Queen'], [11, 12, 13, 14])] }) }) renderPage(, '/mixes', '/mixes') - const card = await screen.findByRole('link', { name: /Rock Mix/ }) - expect(coversOf(card)).toEqual(['/api/v1/albums/11/cover', '/api/v1/albums/12/cover', '/api/v1/albums/13/cover', '/api/v1/albums/14/cover']) + const tile = await screen.findByRole('link', { name: /Rock Mix/ }) + expect(coversOf(tile)).toEqual([]) + expect(tile).toHaveAttribute('data-tone') + expect(tile).toHaveClass('min-h-36', 'text-white') + expect(within(tile).getByText('Rock Mix')).toHaveClass('text-3xl', 'font-extrabold') }) -test('a mix with fewer than four albums shows the first one whole', async () => { - mockFetch({ 'GET /api/v1/mixes': () => ({ items: [mix('genre:rock', 'genre', 'rock', ['Queen'], [11, 12, 13])] }) }) +test('a mix has the same colour every time, and two mixes can have different ones', async () => { + mockFetch({ 'GET /api/v1/mixes': () => ({ items: [mix('favourites', 'favourites', null), mix('rediscover', 'rediscover', null), mix('unheard', 'unheard', null)] }) }) renderPage(, '/mixes', '/mixes') - const card = await screen.findByRole('link', { name: /Rock Mix/ }) - expect(coversOf(card)).toEqual(['/api/v1/albums/11/cover']) -}) - -test('a mix with no cover has the rings in place of a picture', async () => { - mockFetch({ 'GET /api/v1/mixes': () => ({ items: [mix('unheard', 'unheard', null)] }) }) - renderPage(, '/mixes', '/mixes') - const card = await screen.findByRole('link', { name: /New to you/ }) - expect(coversOf(card)).toEqual([]) - expect(card.querySelector('[data-placeholder]')).not.toBeNull() + const tones = (await screen.findAllByRole('link')).map((l) => l.getAttribute('data-tone')) + expect(new Set(tones).size).toBeGreaterThan(1) }) test('the page of a mix shows the same collage', async () => {