Merge pull request 'Mixes as tiles of colour with the name big' (#155) from feat/ui-mixes into main
This commit is contained in:
commit
9c2c5ba884
6 changed files with 54 additions and 43 deletions
|
|
@ -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 },
|
||||
|
|
|
|||
21
web/src/components/tones.ts
Normal file
21
web/src/components/tones.ts
Normal file
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<Link to={`/mixes/${encodeURIComponent(mix.id)}`} className="flex flex-col gap-3 lift">
|
||||
<MixCover albumIds={mix.album_ids} size={200} fluid />
|
||||
<span className="flex min-w-0 flex-col">
|
||||
<span className="truncate font-bold">{mixTitle(t, mix)}</span>
|
||||
<span className="line-clamp-2 text-sm text-muted-foreground">{mix.artists.join(', ')}</span>
|
||||
</span>
|
||||
<Link
|
||||
to={`/mixes/${encodeURIComponent(mix.id)}`}
|
||||
data-tone={tone}
|
||||
style={{ background: TONES[tone].bg }}
|
||||
className="flex min-h-36 flex-col justify-between gap-6 rounded-md p-5 text-white lift focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring"
|
||||
>
|
||||
<span className="text-3xl leading-[1.05] font-extrabold tracking-tight">{mixTitle(t, mix)}</span>
|
||||
<span className="text-[13px]">{t(mix.kind === 'genre' ? 'mixes.fromGenres' : 'mixes.fromListening')}</span>
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
|
|
@ -41,12 +46,12 @@ export default function MixesPage() {
|
|||
<>
|
||||
{forYou.length > 0 && (
|
||||
<Section title={t('mixes.forYou')}>
|
||||
<div className={CARD_GRID}>{forYou.map((m) => <MixCard key={m.id} mix={m} />)}</div>
|
||||
<div className={TILES}>{forYou.map((m) => <MixCard key={m.id} mix={m} />)}</div>
|
||||
</Section>
|
||||
)}
|
||||
{genres.length > 0 && (
|
||||
<Section title={t('mixes.byGenre')}>
|
||||
<div className={CARD_GRID}>{genres.map((m) => <MixCard key={m.id} mix={m} />)}</div>
|
||||
<div className={TILES}>{genres.map((m) => <MixCard key={m.id} mix={m} />)}</div>
|
||||
</Section>
|
||||
)}
|
||||
</>
|
||||
|
|
|
|||
|
|
@ -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(<MixesPage />, '/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(<MixesPage />, '/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(<MixesPage />, '/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 () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue