feat(web): new look, part 1: palette, Figtree, menu, covers and controls
The first piece of the new look of the web app. - The Sonda theme takes the new palette (a deep blue ground, a lighter tone for panels instead of shadows, teal for the action). Every theme gets a --friend colour for what comes from another Sonda server, checked for contrast on the page and on a panel and for a hue that is not the primary one. - Figtree is the only font; Fraunces is gone, also from the full-screen player. - The menu is words and a dot: the dot of the open page is the colour of this server, and the dot of Friends is always the colour of what comes from elsewhere. There is nothing to fold, so the fold button and its setting are removed. - The shell is flat: the menu has a line on its right, the page has no panel around it, the player is a band under everything. - A missing cover is the rings of Sonda on a colour taken from the album, the same one every time; a friend's album gets another colour than this server's album with the same id. - The switch is a pill with a round knob and the outline button is a line.
This commit is contained in:
parent
9b81b6385a
commit
945aaf1a05
18 changed files with 219 additions and 211 deletions
|
|
@ -5,7 +5,7 @@
|
|||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<link rel="icon" type="image/png" sizes="192x192" href="/icon-192.png" />
|
||||
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
|
||||
<meta name="theme-color" content="#041d3a" />
|
||||
<meta name="theme-color" content="#08161d" />
|
||||
<link rel="manifest" href="/manifest.webmanifest" />
|
||||
<meta name="mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-title" content="Sonda" />
|
||||
|
|
|
|||
14
web/package-lock.json
generated
14
web/package-lock.json
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -86,3 +86,33 @@ test('the cover of a friend’s album comes through this server, from the friend
|
|||
const { container } = render(<Cover albumId={12} friend={3} size={64} />)
|
||||
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(<Cover albumId={null} size={64} />)
|
||||
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(<Cover albumId={id} friend={friend} size={64} />)
|
||||
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(<Cover albumId={12} size={64} />)
|
||||
expect(placeholder(container)).toBeNull()
|
||||
fireEvent.error(container.querySelector('img')!)
|
||||
expect(placeholder(container)).not.toBeNull()
|
||||
expect(container.querySelector('img')).toBeNull()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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<string | null>(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 (
|
||||
<div
|
||||
style={fluid ? { width: '100%', maxWidth: size, aspectRatio: '1 / 1' } : { width: size, height: size }}
|
||||
className="relative shrink-0 overflow-hidden rounded-md bg-muted"
|
||||
data-tone={tone}
|
||||
style={{ ...(fluid ? { width: '100%', maxWidth: size, aspectRatio: '1 / 1' } : { width: size, height: size }), ...(showImage ? {} : { background: bg }) }}
|
||||
className="relative shrink-0 overflow-hidden rounded-sm bg-muted"
|
||||
>
|
||||
{showImage ? (
|
||||
<img
|
||||
src={src}
|
||||
alt=""
|
||||
loading="lazy"
|
||||
className="size-full object-cover"
|
||||
onError={() => setFailed(src)}
|
||||
/>
|
||||
<img src={src} alt="" loading="lazy" className="size-full object-cover" onError={() => setFailed(src)} />
|
||||
) : (
|
||||
<svg data-placeholder viewBox="0 0 100 100" className="size-full text-primary" aria-hidden="true">
|
||||
<circle cx="50" cy="50" r="10" fill="none" stroke="currentColor" strokeWidth="2.5" />
|
||||
<circle cx="50" cy="50" r="24" fill="none" stroke="currentColor" strokeWidth="2.5" opacity="0.6" />
|
||||
<circle cx="50" cy="50" r="38" fill="none" stroke="currentColor" strokeWidth="2.5" opacity="0.3" />
|
||||
</svg>
|
||||
<div data-placeholder aria-hidden="true" className="size-full">
|
||||
{RINGS.map((r) => (
|
||||
<span
|
||||
key={r.size}
|
||||
data-ring
|
||||
className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 rounded-full border-[3px]"
|
||||
style={{ width: r.size, height: r.size, borderColor: ring, opacity: r.opacity }}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ export default function NowPlaying() {
|
|||
|
||||
<div className="flex min-w-0 flex-[1_1_380px] flex-col gap-7">
|
||||
<div className="flex flex-col gap-2">
|
||||
<DialogTitle className="font-display text-4xl leading-tight font-semibold tracking-tight md:text-6xl">
|
||||
<DialogTitle className="text-4xl leading-tight font-extrabold tracking-tight md:text-6xl">
|
||||
{track.title}
|
||||
</DialogTitle>
|
||||
<p className="text-xl font-semibold">
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ export default function PlayerBar() {
|
|||
return (
|
||||
<footer
|
||||
aria-label={t('player.label')}
|
||||
className="player-bar gap-x-4 gap-y-1 rounded-xl bg-card px-4 py-2 text-card-foreground sm:gap-x-6 sm:px-5 sm:py-3"
|
||||
className="player-bar gap-x-4 gap-y-1 border-t border-border bg-card px-4 py-2 text-card-foreground sm:gap-x-6 sm:px-8 sm:py-3"
|
||||
>
|
||||
<div className="player-info flex min-w-0 items-center gap-3">
|
||||
{track ? (
|
||||
|
|
|
|||
|
|
@ -24,19 +24,19 @@ export default function Shell() {
|
|||
>
|
||||
{t('app.skip')}
|
||||
</a>
|
||||
<div className="flex flex-1 flex-wrap gap-2 p-2">
|
||||
<div className="flex flex-1 flex-wrap content-start sm:content-stretch">
|
||||
<Sidebar />
|
||||
<main
|
||||
id="main"
|
||||
ref={main}
|
||||
tabIndex={-1}
|
||||
className="min-w-0 flex-[999_1_560px] rounded-xl bg-card p-6 text-card-foreground outline-none"
|
||||
className="min-w-0 flex-[999_1_560px] px-5 py-6 outline-none sm:px-14 sm:py-11"
|
||||
>
|
||||
<Outlet />
|
||||
</main>
|
||||
</div>
|
||||
{/* Sticky here, not on the bar: a sticky element only sticks inside its parent. */}
|
||||
<div className="sticky bottom-0 z-10 bg-background px-2 pb-2">
|
||||
<div className="sticky bottom-0 z-10">
|
||||
<PlayerBar />
|
||||
</div>
|
||||
<UpdateNotice />
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { render, screen, within } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { MemoryRouter } from 'react-router-dom'
|
||||
import { beforeEach, expect, test, vi } from 'vitest'
|
||||
import { sessionStore } from '@/auth/session'
|
||||
|
|
@ -8,20 +7,17 @@ import { initI18n } from '@/i18n'
|
|||
import { mockFetch } from '@/test/mockFetch'
|
||||
import Sidebar from './Sidebar'
|
||||
|
||||
const KEY = 'sonda.sidebar'
|
||||
|
||||
beforeEach(async () => {
|
||||
localStorage.clear()
|
||||
vi.spyOn(navigator, 'language', 'get').mockReturnValue('en-US')
|
||||
await initI18n()
|
||||
sessionStore.setState({ status: 'authenticated', user: { id: 1, email: 'tom@example.org', is_admin: true } })
|
||||
})
|
||||
|
||||
function renderSidebar(friends: { id: number; name: string }[] = []) {
|
||||
function renderSidebar(friends: { id: number; name: string }[] = [], path = '/albums') {
|
||||
mockFetch({ 'GET /api/v1/friends': () => ({ friends }) })
|
||||
render(
|
||||
<QueryClientProvider client={new QueryClient({ defaultOptions: { queries: { retry: false } } })}>
|
||||
<MemoryRouter initialEntries={['/albums']}>
|
||||
<MemoryRouter initialEntries={[path]}>
|
||||
<Sidebar />
|
||||
</MemoryRouter>
|
||||
</QueryClientProvider>,
|
||||
|
|
@ -29,60 +25,39 @@ function renderSidebar(friends: { id: number; name: string }[] = []) {
|
|||
return screen.getByRole('navigation', { name: 'Main' })
|
||||
}
|
||||
|
||||
test('the sidebar starts open, with a button that folds it', () => {
|
||||
test('the menu is words, one for each page, and the page that is open is the current one', () => {
|
||||
const nav = renderSidebar()
|
||||
expect(nav).toHaveAttribute('data-collapsed', 'false')
|
||||
expect(within(nav).getByRole('button', { name: 'Collapse the sidebar' })).toBeInTheDocument()
|
||||
expect(within(nav).getByText('Albums')).toBeVisible()
|
||||
})
|
||||
|
||||
test('folded, it keeps every link with its name and a tooltip, and the same button opens it again', async () => {
|
||||
const nav = renderSidebar()
|
||||
await userEvent.click(within(nav).getByRole('button', { name: 'Collapse the sidebar' }))
|
||||
expect(nav).toHaveAttribute('data-collapsed', 'true')
|
||||
const albums = within(nav).getByRole('link', { name: 'Albums' })
|
||||
expect(albums).toHaveAttribute('aria-current', 'page')
|
||||
expect(albums).toHaveAttribute('title', 'Albums')
|
||||
for (const name of ['Home', 'Search', 'Mixes', 'Playlists', 'Smart playlists', 'Admin', 'Settings']) {
|
||||
for (const name of ['Home', 'Search', 'Discover', 'Artists', 'Albums', 'Songs', 'Mixes', 'Playlists', 'Smart playlists', 'Admin', 'Settings']) {
|
||||
expect(within(nav).getByRole('link', { name })).toBeInTheDocument()
|
||||
}
|
||||
await userEvent.click(within(nav).getByRole('button', { name: 'Expand the sidebar' }))
|
||||
expect(nav).toHaveAttribute('data-collapsed', 'false')
|
||||
expect(within(nav).getByRole('link', { name: 'Albums' })).not.toHaveAttribute('title')
|
||||
expect(within(nav).getByRole('link', { name: 'Albums' })).toHaveAttribute('aria-current', 'page')
|
||||
expect(within(nav).getByRole('link', { name: 'Artists' })).not.toHaveAttribute('aria-current')
|
||||
// No icons, the words are enough: the only drawing in the menu is the logo.
|
||||
expect([...nav.querySelectorAll('svg')].filter((svg) => svg.getAttribute('role') !== 'img')).toHaveLength(0)
|
||||
})
|
||||
|
||||
test('folded, the logo shrinks to its wave and the word is still the name of the app', async () => {
|
||||
test('there is nothing to fold: the menu always shows its words', () => {
|
||||
const nav = renderSidebar()
|
||||
expect(nav).not.toHaveAttribute('data-collapsed')
|
||||
expect(within(nav).queryByRole('button')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('a dot marks the page that is open, in the colour of this server', () => {
|
||||
const nav = renderSidebar()
|
||||
const dot = (name: string) => within(nav).getByRole('link', { name }).querySelector('[data-dot]')
|
||||
expect(dot('Albums')).toHaveClass('bg-primary')
|
||||
expect(dot('Artists')).toHaveClass('bg-transparent')
|
||||
})
|
||||
|
||||
test('the Sonda logo is the name of the app', () => {
|
||||
const nav = renderSidebar()
|
||||
expect(within(nav).getAllByRole('img', { name: 'Sonda' })).toHaveLength(1)
|
||||
await userEvent.click(within(nav).getByRole('button', { name: 'Collapse the sidebar' }))
|
||||
const logos = within(nav).getAllByRole('img', { name: 'Sonda' })
|
||||
expect(logos).toHaveLength(2) // the word (hidden from the wide bar) and the wave
|
||||
expect(logos.filter((l) => l.classList.contains('sm:hidden'))).toHaveLength(1)
|
||||
expect(logos.filter((l) => l.classList.contains('sm:block'))).toHaveLength(1)
|
||||
})
|
||||
|
||||
test('the choice is remembered in the browser', async () => {
|
||||
const first = renderSidebar()
|
||||
await userEvent.click(within(first).getByRole('button', { name: 'Collapse the sidebar' }))
|
||||
expect(JSON.parse(localStorage.getItem(KEY) ?? 'null')).toBe('collapsed')
|
||||
document.body.innerHTML = ''
|
||||
const second = renderSidebar()
|
||||
expect(second).toHaveAttribute('data-collapsed', 'true')
|
||||
await userEvent.click(within(second).getByRole('button', { name: 'Expand the sidebar' }))
|
||||
expect(JSON.parse(localStorage.getItem(KEY) ?? 'null')).toBe('open')
|
||||
})
|
||||
|
||||
test('a browser that will not keep it still folds and opens the sidebar', async () => {
|
||||
vi.spyOn(Storage.prototype, 'getItem').mockImplementation(() => {
|
||||
throw new Error('blocked')
|
||||
})
|
||||
vi.spyOn(Storage.prototype, 'setItem').mockImplementation(() => {
|
||||
throw new Error('blocked')
|
||||
})
|
||||
test('only an admin has an Admin link', () => {
|
||||
sessionStore.setState({ status: 'authenticated', user: { id: 2, email: 'ann@example.org', is_admin: false } })
|
||||
const nav = renderSidebar()
|
||||
expect(nav).toHaveAttribute('data-collapsed', 'false')
|
||||
await userEvent.click(within(nav).getByRole('button', { name: 'Collapse the sidebar' }))
|
||||
expect(nav).toHaveAttribute('data-collapsed', 'true')
|
||||
expect(within(nav).queryByRole('link', { name: 'Admin' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('Friends is in the menu only when there is a friend to browse', async () => {
|
||||
|
|
@ -91,7 +66,16 @@ test('Friends is in the menu only when there is a friend to browse', async () =>
|
|||
expect(within(none).queryByRole('link', { name: 'Friends' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('with a friend the menu has a Friends link', async () => {
|
||||
test('with a friend the menu has a Friends link, with the dot of what comes from elsewhere', async () => {
|
||||
const nav = renderSidebar([{ id: 3, name: 'Anna' }])
|
||||
expect(await within(nav).findByRole('link', { name: 'Friends' })).toHaveAttribute('href', '/friends')
|
||||
const link = await within(nav).findByRole('link', { name: 'Friends' })
|
||||
expect(link).toHaveAttribute('href', '/friends')
|
||||
expect(link.querySelector('[data-dot]')).toHaveClass('bg-friend')
|
||||
})
|
||||
|
||||
test('the dot of Friends is the friend colour also when it is the page that is open', async () => {
|
||||
const nav = renderSidebar([{ id: 3, name: 'Anna' }], '/friends/3')
|
||||
const link = await within(nav).findByRole('link', { name: 'Friends' })
|
||||
expect(link).toHaveAttribute('aria-current', 'page')
|
||||
expect(link.querySelector('[data-dot]')).toHaveClass('bg-friend')
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,7 +1,3 @@
|
|||
import {
|
||||
Compass, Disc3, House, ListMusic, Mic2, Music, PanelLeftClose, PanelLeftOpen, Search, Settings, ShieldCheck, Sparkles, Users, Wand2, type LucideIcon,
|
||||
} from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { NavLink } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useFriends } from '@/api/friends'
|
||||
|
|
@ -9,110 +5,68 @@ import { useSession } from '@/auth/session'
|
|||
import Logo from '@/components/Logo'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
const LINKS: { to: string; key: string; icon: LucideIcon; end: boolean; adminOnly: boolean; friends?: boolean }[] = [
|
||||
{ to: '/', key: 'nav.home', icon: House, end: true, adminOnly: false },
|
||||
{ to: '/search', key: 'nav.search', icon: Search, end: false, adminOnly: false },
|
||||
{ to: '/discover', key: 'nav.discover', icon: Compass, end: false, adminOnly: false },
|
||||
{ to: '/artists', key: 'nav.artists', icon: Mic2, end: false, adminOnly: false },
|
||||
{ to: '/albums', key: 'nav.albums', icon: Disc3, end: false, adminOnly: false },
|
||||
{ to: '/songs', key: 'nav.songs', icon: Music, end: false, adminOnly: false },
|
||||
{ to: '/mixes', key: 'nav.mixes', icon: Sparkles, end: false, adminOnly: false },
|
||||
{ to: '/playlists', key: 'nav.playlists', icon: ListMusic, end: false, adminOnly: false },
|
||||
{ to: '/smart-playlists', key: 'nav.smartPlaylists', icon: Wand2, end: false, adminOnly: false },
|
||||
{ to: '/friends', key: 'nav.friends', icon: Users, end: false, adminOnly: false, friends: true },
|
||||
{ to: '/admin', key: 'nav.admin', icon: ShieldCheck, end: false, adminOnly: true },
|
||||
{ to: '/settings', key: 'nav.settings', icon: Settings, end: false, adminOnly: false },
|
||||
const LINKS: { to: string; key: string; end: boolean; adminOnly: boolean; friends?: boolean }[] = [
|
||||
{ to: '/', key: 'nav.home', end: true, adminOnly: false },
|
||||
{ to: '/search', key: 'nav.search', end: false, adminOnly: false },
|
||||
{ to: '/discover', key: 'nav.discover', end: false, adminOnly: false },
|
||||
{ to: '/artists', key: 'nav.artists', end: false, adminOnly: false },
|
||||
{ to: '/albums', key: 'nav.albums', end: false, adminOnly: false },
|
||||
{ to: '/songs', key: 'nav.songs', end: false, adminOnly: false },
|
||||
{ to: '/mixes', key: 'nav.mixes', end: false, adminOnly: false },
|
||||
{ to: '/playlists', key: 'nav.playlists', end: false, adminOnly: false },
|
||||
{ to: '/smart-playlists', key: 'nav.smartPlaylists', end: false, adminOnly: false },
|
||||
{ to: '/friends', key: 'nav.friends', end: false, adminOnly: false, friends: true },
|
||||
{ to: '/admin', key: 'nav.admin', end: false, adminOnly: true },
|
||||
{ to: '/settings', key: 'nav.settings', end: false, adminOnly: false },
|
||||
]
|
||||
|
||||
const KEY = 'sonda.sidebar'
|
||||
|
||||
function readCollapsed(): boolean {
|
||||
try {
|
||||
return JSON.parse(localStorage.getItem(KEY) ?? 'null') === 'collapsed'
|
||||
} catch {
|
||||
return false // a browser that will not say: open
|
||||
}
|
||||
}
|
||||
|
||||
function writeCollapsed(collapsed: boolean) {
|
||||
try {
|
||||
localStorage.setItem(KEY, JSON.stringify(collapsed ? 'collapsed' : 'open'))
|
||||
} catch {
|
||||
// The sidebar still folds; it just opens again at the next visit.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The main menu. On a screen wide enough it can fold to a narrow bar with the icons of the pages, and the choice is
|
||||
* remembered in the browser. On a phone it is a row of links and never folds.
|
||||
* The main menu: words, one for each page, and a dot that says which one is open. The dot is the colour of this
|
||||
* server; for Friends it is the colour of what comes from elsewhere, always, so that the one page that shows other
|
||||
* people's music is told apart before it is opened. On a phone the menu is a row of links that scrolls sideways.
|
||||
*/
|
||||
export default function Sidebar() {
|
||||
const { t } = useTranslation()
|
||||
const { user } = useSession()
|
||||
const [collapsed, setCollapsed] = useState(readCollapsed)
|
||||
// Friends is in the menu only when there is a friend to browse (federation on, and a friendship both admins agreed to).
|
||||
const hasFriends = (useFriends().data?.length ?? 0) > 0
|
||||
const links = LINKS.filter((link) => (!link.adminOnly || user?.is_admin) && (!link.friends || hasFriends))
|
||||
|
||||
function toggle() {
|
||||
writeCollapsed(!collapsed)
|
||||
setCollapsed(!collapsed)
|
||||
}
|
||||
|
||||
// Folding only counts from the `sm` width up: below it the sidebar is a row, which has no room to gain.
|
||||
return (
|
||||
<nav
|
||||
aria-label={t('nav.main')}
|
||||
data-collapsed={collapsed}
|
||||
className={cn(
|
||||
'flex flex-[0_0_248px] flex-col gap-6 rounded-xl bg-card p-5 text-card-foreground max-sm:min-w-0 max-sm:flex-[1_1_100%] max-sm:gap-3 max-sm:p-3',
|
||||
collapsed && 'sm:flex-[0_0_72px] sm:items-center sm:p-3',
|
||||
)}
|
||||
className="flex flex-[0_0_232px] flex-col gap-0.5 border-r border-border px-5 py-8 max-sm:min-w-0 max-sm:flex-[1_1_100%] max-sm:gap-3 max-sm:border-r-0 max-sm:border-b max-sm:p-3"
|
||||
>
|
||||
<div className={cn('flex items-center gap-3', collapsed && 'sm:flex-col')}>
|
||||
{/* The word, or only its wave when the bar is folded (never on a phone, where the bar is a row). */}
|
||||
<Logo name={t('app.name')} className={cn('h-7 w-auto shrink-0', collapsed && 'sm:hidden')} />
|
||||
{collapsed && <Logo mark name={t('app.name')} className="hidden size-8 shrink-0 sm:block" />}
|
||||
<button
|
||||
type="button"
|
||||
onClick={toggle}
|
||||
aria-label={t(collapsed ? 'nav.expand' : 'nav.collapse')}
|
||||
className={cn(
|
||||
'ml-auto flex size-11 items-center justify-center rounded-lg text-muted-foreground hover:bg-secondary hover:text-foreground max-sm:hidden',
|
||||
collapsed && 'sm:ml-0',
|
||||
)}
|
||||
>
|
||||
{collapsed ? <PanelLeftOpen className="size-5" aria-hidden="true" /> : <PanelLeftClose className="size-5" aria-hidden="true" />}
|
||||
</button>
|
||||
</div>
|
||||
<Logo name={t('app.name')} className="mx-3 mb-7 h-8 w-auto self-start max-sm:mb-0" />
|
||||
{/* On a phone the links are one row that scrolls sideways, so that the page keeps the screen. */}
|
||||
<ul className="flex flex-col gap-1 max-sm:min-w-0 max-sm:-mx-3 max-sm:flex-row max-sm:gap-0 max-sm:overflow-x-auto max-sm:px-3 max-sm:pb-1 max-sm:[scrollbar-width:none]">
|
||||
{links.map((link) => {
|
||||
const label = t(link.key)
|
||||
return (
|
||||
<li key={link.to} className="max-sm:shrink-0">
|
||||
<NavLink
|
||||
to={link.to}
|
||||
end={link.end}
|
||||
title={collapsed ? label : undefined}
|
||||
className={({ isActive }) =>
|
||||
cn(
|
||||
'flex min-h-11 items-center gap-3 rounded-lg px-3 font-semibold',
|
||||
collapsed && 'sm:justify-center sm:px-0 sm:size-11',
|
||||
isActive ? 'bg-secondary text-foreground' : 'text-muted-foreground hover:text-foreground',
|
||||
)
|
||||
}
|
||||
>
|
||||
<link.icon className="size-5 shrink-0 max-sm:hidden" aria-hidden="true" />
|
||||
<span className={cn(collapsed && 'sm:sr-only')}>{label}</span>
|
||||
</NavLink>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
<ul className="flex flex-col gap-0.5 max-sm:-mx-3 max-sm:min-w-0 max-sm:flex-row max-sm:gap-0 max-sm:overflow-x-auto max-sm:px-3 max-sm:pb-1 max-sm:[scrollbar-width:none]">
|
||||
{links.map((link) => (
|
||||
<li key={link.to} className="max-sm:shrink-0">
|
||||
<NavLink
|
||||
to={link.to}
|
||||
end={link.end}
|
||||
className={({ isActive }) =>
|
||||
cn(
|
||||
'flex min-h-11 items-center gap-3 rounded-lg px-3 font-medium focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring',
|
||||
isActive ? 'bg-card font-bold text-foreground' : 'text-muted-foreground hover:text-foreground',
|
||||
)
|
||||
}
|
||||
>
|
||||
{({ isActive }) => (
|
||||
<>
|
||||
<span
|
||||
data-dot
|
||||
aria-hidden="true"
|
||||
className={cn('size-2 shrink-0 rounded-full', link.friends ? 'bg-friend' : isActive ? 'bg-primary' : 'bg-transparent')}
|
||||
/>
|
||||
<span>{t(link.key)}</span>
|
||||
</>
|
||||
)}
|
||||
</NavLink>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<p className={cn('mt-auto rounded-lg bg-secondary px-3 py-2.5 text-[13px] text-muted-foreground max-sm:hidden', collapsed && 'sm:hidden')}>
|
||||
{t('app.privacy')}
|
||||
</p>
|
||||
<p className="mt-auto px-3 pt-7 text-[13px] leading-snug text-muted-foreground max-sm:hidden">{t('app.privacy')}</p>
|
||||
</nav>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@ import { cva, type VariantProps } from "class-variance-authority"
|
|||
import { cn } from "cn"
|
||||
|
||||
const buttonVariants = cva(
|
||||
"group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
"group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-semibold whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-primary text-primary-foreground hover:bg-primary/80",
|
||||
outline:
|
||||
"border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
|
||||
"border-input bg-transparent hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground",
|
||||
secondary:
|
||||
"bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
|
||||
ghost:
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ interface SwitchProps extends Omit<ComponentProps<'button'>, 'role' | 'type' | '
|
|||
checked: boolean
|
||||
}
|
||||
|
||||
/** An on/off switch. The button is 44 pixels high so that a thumb finds it; the track drawn inside is smaller. */
|
||||
/** An on/off switch: a pill with a round knob. The button is 44 pixels high so that a thumb finds it; the track drawn inside is 32. */
|
||||
export function Switch({ checked, className, ...props }: SwitchProps) {
|
||||
return (
|
||||
<button
|
||||
|
|
@ -13,7 +13,7 @@ export function Switch({ checked, className, ...props }: SwitchProps) {
|
|||
role="switch"
|
||||
aria-checked={checked}
|
||||
className={cn(
|
||||
'group flex h-11 w-12 shrink-0 items-center rounded-md focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring disabled:opacity-50',
|
||||
'group flex h-11 w-14 shrink-0 items-center rounded-full focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring disabled:opacity-50',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
|
|
@ -21,14 +21,14 @@ export function Switch({ checked, className, ...props }: SwitchProps) {
|
|||
<span
|
||||
aria-hidden="true"
|
||||
className={cn(
|
||||
'relative h-7 w-full rounded-md border border-input transition-colors',
|
||||
checked ? 'bg-primary' : 'bg-secondary',
|
||||
'relative h-8 w-full rounded-full border border-input transition-colors',
|
||||
checked ? 'border-primary bg-primary' : 'bg-secondary',
|
||||
)}
|
||||
>
|
||||
<span
|
||||
className={cn(
|
||||
'absolute top-0.5 left-0.5 size-5 rounded-sm transition-transform motion-reduce:transition-none',
|
||||
checked ? 'translate-x-5 bg-primary-foreground' : 'bg-muted-foreground',
|
||||
'absolute top-0.5 left-0.5 size-6 rounded-full transition-transform motion-reduce:transition-none',
|
||||
checked ? 'translate-x-6 bg-primary-foreground' : 'bg-muted-foreground',
|
||||
)}
|
||||
/>
|
||||
</span>
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@
|
|||
"privacy": "Nothing leaves this server unless an admin turns a provider on."
|
||||
},
|
||||
"nav": {
|
||||
"collapse": "Collapse the sidebar",
|
||||
"expand": "Expand the sidebar",
|
||||
"main": "Main",
|
||||
"home": "Home",
|
||||
"search": "Search",
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@
|
|||
"privacy": "Niente esce da questo server finché un admin non accende un provider."
|
||||
},
|
||||
"nav": {
|
||||
"collapse": "Comprimi la barra laterale",
|
||||
"expand": "Espandi la barra laterale",
|
||||
"main": "Principale",
|
||||
"home": "Home",
|
||||
"search": "Cerca",
|
||||
|
|
|
|||
|
|
@ -6,8 +6,6 @@
|
|||
@import "@fontsource/figtree/600.css";
|
||||
@import "@fontsource/figtree/700.css";
|
||||
@import "@fontsource/figtree/800.css";
|
||||
@import "@fontsource/fraunces/600.css";
|
||||
@import "@fontsource/fraunces/700.css";
|
||||
@import "./theme/themes.css";
|
||||
|
||||
/* The dark variant follows the theme, not the OS setting. */
|
||||
|
|
@ -16,11 +14,12 @@
|
|||
@theme inline {
|
||||
--font-heading: var(--font-sans);
|
||||
--font-sans: 'Figtree', system-ui, sans-serif;
|
||||
--font-display: 'Fraunces', Georgia, serif;
|
||||
--color-ring: var(--ring);
|
||||
--color-input: var(--input);
|
||||
--color-border: var(--border);
|
||||
--color-destructive: var(--destructive);
|
||||
--color-friend-foreground: var(--friend-foreground);
|
||||
--color-friend: var(--friend);
|
||||
--color-accent-foreground: var(--accent-foreground);
|
||||
--color-accent: var(--accent);
|
||||
--color-muted-foreground: var(--muted-foreground);
|
||||
|
|
@ -45,7 +44,7 @@
|
|||
}
|
||||
|
||||
:root {
|
||||
--radius: 0.25rem;
|
||||
--radius: 0.5rem;
|
||||
}
|
||||
|
||||
@layer base {
|
||||
|
|
|
|||
|
|
@ -37,6 +37,10 @@ const pairs: [string, string, number][] = [
|
|||
['primary', 'background', 4.5],
|
||||
['primary', 'card', 4.5],
|
||||
['primary-foreground', 'primary', 4.5],
|
||||
// What comes from a friend's server has its own colour, and it has to be readable on the page and on a panel.
|
||||
['friend', 'background', 4.5],
|
||||
['friend', 'card', 4.5],
|
||||
['friend-foreground', 'friend', 4.5],
|
||||
['primary', 'background', 3],
|
||||
['input', 'background', 3],
|
||||
['input', 'card', 3],
|
||||
|
|
@ -60,3 +64,18 @@ describe.each(THEMES.map((t) => t.id))('theme %s', (id) => {
|
|||
test('the colour given to the browser bar is the background of each theme', () => {
|
||||
for (const t of THEMES) expect(BAR_COLOURS[t.id], t.id).toBe(parseTheme(t.id)['background'])
|
||||
})
|
||||
|
||||
test.each(THEMES.map((t) => t.id))('in %s the colour of a friend is not the colour of this server', (id) => {
|
||||
const tokens = parseTheme(id)
|
||||
// Told apart by lightness as well as by hue is not possible for every pair of accents, so it is the hue that has to differ.
|
||||
const hue = (hex: string) => {
|
||||
const [r, g, b] = [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16) / 255)
|
||||
const max = Math.max(r, g, b)
|
||||
const d = max - Math.min(r, g, b)
|
||||
if (d === 0) return 0
|
||||
const h = max === r ? ((g - b) / d) % 6 : max === g ? (b - r) / d + 2 : (r - g) / d + 4
|
||||
return (h * 60 + 360) % 360
|
||||
}
|
||||
const apart = Math.abs(hue(tokens['friend']) - hue(tokens['primary']))
|
||||
expect(Math.min(apart, 360 - apart)).toBeGreaterThanOrEqual(40)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ export const THEMES: readonly { id: ThemeId; labelKey: string }[] = [
|
|||
|
||||
/** The background of each theme (a test keeps this in step with themes.css): the browser paints its bar with it. */
|
||||
export const BAR_COLOURS: Record<ThemeId, string> = {
|
||||
sonda: '#0a1218',
|
||||
sonda: '#08161d',
|
||||
'tokyo-night': '#1a1b26',
|
||||
'gruvbox-dark': '#282828',
|
||||
'gruvbox-light': '#fbf1c7',
|
||||
|
|
|
|||
|
|
@ -1,29 +1,32 @@
|
|||
/*
|
||||
* The six themes. Every colour is a plain hex value so that contrast.test.ts can check it.
|
||||
* Token names are the ones shadcn/ui uses.
|
||||
* Token names are the ones shadcn/ui uses, plus --friend: what comes from another Sonda server (a friend's music) has
|
||||
* its own colour, as the primary colour says "here". It is told apart from the primary by its hue.
|
||||
* --border is a quiet divider; --input is the outline of a form control and has to be seen (3:1).
|
||||
*/
|
||||
|
||||
[data-theme="sonda"] {
|
||||
color-scheme: dark;
|
||||
--background: #0a1218;
|
||||
--foreground: #e8f1f2;
|
||||
--card: #111c24;
|
||||
--card-foreground: #e8f1f2;
|
||||
--popover: #111c24;
|
||||
--popover-foreground: #e8f1f2;
|
||||
--primary: #3dd6b0;
|
||||
--primary-foreground: #04231c;
|
||||
--secondary: #182630;
|
||||
--secondary-foreground: #e8f1f2;
|
||||
--muted: #182630;
|
||||
--muted-foreground: #93a7ae;
|
||||
--accent: #182630;
|
||||
--accent-foreground: #e8f1f2;
|
||||
--destructive: #ff7a8a;
|
||||
--border: #1e2f3a;
|
||||
--input: #5e7a87;
|
||||
--ring: #3dd6b0;
|
||||
--background: #08161d;
|
||||
--foreground: #e8f3f1;
|
||||
--card: #0f2530;
|
||||
--card-foreground: #e8f3f1;
|
||||
--popover: #0f2530;
|
||||
--popover-foreground: #e8f3f1;
|
||||
--primary: #37e0c2;
|
||||
--primary-foreground: #062a25;
|
||||
--secondary: #183644;
|
||||
--secondary-foreground: #e8f3f1;
|
||||
--muted: #183644;
|
||||
--muted-foreground: #93b2b4;
|
||||
--accent: #183644;
|
||||
--accent-foreground: #e8f3f1;
|
||||
--friend: #f0b35f;
|
||||
--friend-foreground: #2b1a02;
|
||||
--destructive: #ff8a7a;
|
||||
--border: #183644;
|
||||
--input: #4a8499;
|
||||
--ring: #37e0c2;
|
||||
}
|
||||
|
||||
[data-theme="tokyo-night"] {
|
||||
|
|
@ -42,6 +45,8 @@
|
|||
--muted-foreground: #9aa5ce;
|
||||
--accent: #2f3549;
|
||||
--accent-foreground: #c0caf5;
|
||||
--friend: #e0af68;
|
||||
--friend-foreground: #1a1b26;
|
||||
--destructive: #f7768e;
|
||||
--border: #3b4261;
|
||||
--input: #7982aa;
|
||||
|
|
@ -64,6 +69,8 @@
|
|||
--muted-foreground: #d5c4a1;
|
||||
--accent: #504945;
|
||||
--accent-foreground: #ebdbb2;
|
||||
--friend: #8ec07c;
|
||||
--friend-foreground: #282828;
|
||||
--destructive: #fb4934;
|
||||
--border: #504945;
|
||||
--input: #928374;
|
||||
|
|
@ -87,6 +94,8 @@
|
|||
--muted-foreground: #b4b8d4;
|
||||
--accent: #44475a;
|
||||
--accent-foreground: #f8f8f2;
|
||||
--friend: #8be9fd;
|
||||
--friend-foreground: #282a36;
|
||||
--destructive: #ff5555;
|
||||
--border: #44475a;
|
||||
--input: #7081b8;
|
||||
|
|
@ -110,6 +119,8 @@
|
|||
--muted-foreground: #d4c2ff;
|
||||
--accent: #5a2fd0;
|
||||
--accent-foreground: #fff4ff;
|
||||
--friend: #3ee6ff;
|
||||
--friend-foreground: #14073d;
|
||||
--destructive: #ff6b81;
|
||||
--border: #4a22b0;
|
||||
--input: #9b85ff;
|
||||
|
|
@ -132,6 +143,8 @@
|
|||
--muted-foreground: #504945;
|
||||
--accent: #d5c4a1;
|
||||
--accent-foreground: #3c3836;
|
||||
--friend: #076678;
|
||||
--friend-foreground: #fbf1c7;
|
||||
--destructive: #9d0006;
|
||||
--border: #d5c4a1;
|
||||
--input: #7c6f64;
|
||||
|
|
|
|||
Loading…
Reference in a new issue