fix(web): tap targets of 44 px, a browser bar that follows the theme, shorter lines
- The switches and the seek bar of the player bar take a tap on 44 px (the switch is now one component). - The colour of the browser bar follows the theme instead of staying dark blue. - Paragraphs stop at 56 characters and no longer end on a lone word. Closes #130
This commit is contained in:
parent
a423632632
commit
f0135cc548
21 changed files with 132 additions and 57 deletions
|
|
@ -4,8 +4,8 @@ import { ApiError } from '@/api/client'
|
|||
import { useMySettings, useUpdateSettings } from '@/api/discover'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { errorMessageKey } from '@/i18n'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
/**
|
||||
* Whether Discover may start from the artists you play most. Turning it on sends their names to Last.fm
|
||||
|
|
@ -26,26 +26,12 @@ export default function ListeningSwitch() {
|
|||
return (
|
||||
<div className="flex max-w-xl flex-col gap-3">
|
||||
<div className="flex items-center gap-4">
|
||||
<button
|
||||
type="button"
|
||||
role="switch"
|
||||
aria-checked={on}
|
||||
<Switch
|
||||
checked={on}
|
||||
aria-labelledby="listening-label"
|
||||
disabled={settings.data === undefined || update.isPending}
|
||||
onClick={() => (on ? change(false) : setAsking(true))}
|
||||
className={cn(
|
||||
'relative h-7 w-12 shrink-0 rounded-md border border-input transition-colors focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring disabled:opacity-50',
|
||||
on ? 'bg-primary' : 'bg-secondary',
|
||||
)}
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className={cn(
|
||||
'absolute top-0.5 left-0.5 size-5 rounded-sm transition-transform motion-reduce:transition-none',
|
||||
on ? 'translate-x-5 bg-primary-foreground' : 'bg-muted-foreground',
|
||||
)}
|
||||
/>
|
||||
</button>
|
||||
/>
|
||||
<span id="listening-label" className="font-semibold">
|
||||
{t('discover.listening.label')}
|
||||
</span>
|
||||
|
|
|
|||
7
web/src/components/RouteLoading.tsx
Normal file
7
web/src/components/RouteLoading.tsx
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
/** What is on screen while the first page of a lazy route is being fetched. */
|
||||
export default function RouteLoading() {
|
||||
const { t } = useTranslation()
|
||||
return <div role="status" aria-label={t('common.loading')} className="min-h-screen bg-background" />
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ export default function Scrubber({ positionMs, durationMs, onSeek, variant }: Sc
|
|||
onChange={(e) => onSeek(Number(e.target.value))}
|
||||
className={cn(
|
||||
'cursor-pointer disabled:cursor-default',
|
||||
variant === 'line' ? 'h-6 w-full accent-primary' : 'absolute inset-0 h-full w-full opacity-0',
|
||||
variant === 'line' ? '-my-2 h-11 w-full accent-primary' : 'absolute inset-0 h-full w-full opacity-0',
|
||||
)}
|
||||
/>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -321,3 +321,8 @@ test('the controls and the title do not render again when only the position move
|
|||
act(() => usePlayer.getState().tick(6_000))
|
||||
expect(commits).toBe(before)
|
||||
})
|
||||
|
||||
test('the seek bar of the player bar is 44 pixels high to take a thumb', () => {
|
||||
render(<Scrubber positionMs={0} durationMs={1000} onSeek={() => {}} variant="line" />)
|
||||
expect(screen.getByRole('slider')).toHaveClass('h-11')
|
||||
})
|
||||
|
|
|
|||
23
web/src/components/ui/switch.test.tsx
Normal file
23
web/src/components/ui/switch.test.tsx
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { expect, test, vi } from 'vitest'
|
||||
import { Switch } from './switch'
|
||||
|
||||
test('it is a switch that says whether it is on and reports a click', async () => {
|
||||
const onClick = vi.fn()
|
||||
render(<Switch checked={false} aria-label="Wi-Fi" onClick={onClick} />)
|
||||
const sw = screen.getByRole('switch', { name: 'Wi-Fi' })
|
||||
expect(sw).toHaveAttribute('aria-checked', 'false')
|
||||
await userEvent.click(sw)
|
||||
expect(onClick).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
test('the area that takes a tap is 44 pixels high, and a disabled switch ignores taps', async () => {
|
||||
const onClick = vi.fn()
|
||||
render(<Switch checked disabled aria-label="Wi-Fi" onClick={onClick} />)
|
||||
const sw = screen.getByRole('switch')
|
||||
expect(sw).toHaveClass('h-11')
|
||||
expect(sw).toHaveAttribute('aria-checked', 'true')
|
||||
await userEvent.click(sw)
|
||||
expect(onClick).not.toHaveBeenCalled()
|
||||
})
|
||||
37
web/src/components/ui/switch.tsx
Normal file
37
web/src/components/ui/switch.tsx
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import type { ComponentProps } from 'react'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
interface SwitchProps extends Omit<ComponentProps<'button'>, 'role' | 'type' | 'children'> {
|
||||
checked: boolean
|
||||
}
|
||||
|
||||
/** An on/off switch. The button is 44 pixels high so that a thumb finds it; the track drawn inside is smaller. */
|
||||
export function Switch({ checked, className, ...props }: SwitchProps) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
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',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className={cn(
|
||||
'relative h-7 w-full rounded-md border border-input transition-colors',
|
||||
checked ? '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',
|
||||
)}
|
||||
/>
|
||||
</span>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
|
@ -52,6 +52,16 @@
|
|||
* {
|
||||
@apply border-border outline-ring/50;
|
||||
}
|
||||
/* A line of reading stays readable on a wide screen, and no line ends on a lone word. */
|
||||
p {
|
||||
max-width: 56ch;
|
||||
text-wrap: pretty;
|
||||
}
|
||||
h1,
|
||||
h2,
|
||||
h3 {
|
||||
text-wrap: balance;
|
||||
}
|
||||
body {
|
||||
@apply bg-background text-foreground;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ function MixView({ id }: { id: string }) {
|
|||
<MixCover albumIds={mix.album_ids} size={232} fluid />
|
||||
<div className="flex min-w-0 flex-1 basis-80 flex-col gap-3">
|
||||
<h1 className="text-4xl font-extrabold tracking-tight md:text-6xl">{title}</h1>
|
||||
{mix.artists.length > 0 && <p className="max-w-2xl text-muted-foreground">{t('mixes.with', { artists: mix.artists.join(', ') })}</p>}
|
||||
{mix.artists.length > 0 && <p className="text-muted-foreground">{t('mixes.with', { artists: mix.artists.join(', ') })}</p>}
|
||||
<p className="text-muted-foreground">{t('playlists.meta', { count: mix.tracks.length, duration: formatTime(duration) })}</p>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button className="h-12 gap-2 rounded-md px-6" disabled={empty} onClick={() => playTracks(mix.tracks, 0)}>
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ function PlaylistView({ id }: { id: number }) {
|
|||
<MixCover albumIds={p.album_ids} size={232} fluid />
|
||||
<div className="flex min-w-0 flex-1 basis-80 flex-col gap-3">
|
||||
<h1 className="text-4xl font-extrabold tracking-tight md:text-6xl">{p.name}</h1>
|
||||
{p.description && <p className="max-w-2xl text-muted-foreground">{p.description}</p>}
|
||||
{p.description && <p className="text-muted-foreground">{p.description}</p>}
|
||||
<p className="text-muted-foreground">{t('playlists.meta', { count: p.track_count, duration: formatTime(p.duration_ms) })}</p>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button className="h-12 gap-2 rounded-md px-6" disabled={playableIds.length === 0} onClick={() => play(null)}>
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ export default function SettingsPage() {
|
|||
|
||||
{app.available && (
|
||||
<Section title={t('settings.app')}>
|
||||
<p className="max-w-2xl text-muted-foreground">{t('pwa.installIntro')}</p>
|
||||
<p className="text-muted-foreground">{t('pwa.installIntro')}</p>
|
||||
<Button className="self-start" onClick={() => void app.install()}>
|
||||
{t('pwa.install')}
|
||||
</Button>
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ function SmartView({ id }: { id: number }) {
|
|||
<MixCover albumIds={covers.data ?? []} size={232} fluid />
|
||||
<div className="flex min-w-0 flex-1 basis-80 flex-col gap-3">
|
||||
<h1 className="text-4xl font-extrabold tracking-tight md:text-6xl">{p.name}</h1>
|
||||
{p.description && <p className="max-w-2xl text-muted-foreground">{p.description}</p>}
|
||||
{p.description && <p className="text-muted-foreground">{p.description}</p>}
|
||||
<ul aria-label={t('smart.rulesTitle')} className="flex flex-wrap gap-2">
|
||||
{describeRules(t, p.rules).map((line) => (
|
||||
<li key={line} className="rounded-md bg-secondary px-3 py-1 text-sm font-semibold">
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ function SuggestedView({ name: key }: { name: string }) {
|
|||
<MixCover albumIds={covers.data ?? []} size={232} fluid />
|
||||
<div className="flex min-w-0 flex-1 basis-80 flex-col gap-3">
|
||||
<h1 className="text-4xl font-extrabold tracking-tight md:text-6xl">{title}</h1>
|
||||
<p className="max-w-2xl text-muted-foreground">{description}</p>
|
||||
<p className="text-muted-foreground">{description}</p>
|
||||
<ul aria-label={t('smart.rulesTitle')} className="flex flex-wrap gap-2">
|
||||
{describeRules(t, suggested.rules).map((line) => (
|
||||
<li key={line} className="rounded-md bg-secondary px-3 py-1 text-sm font-semibold">
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ export default function CostsPage() {
|
|||
|
||||
return (
|
||||
<Section title={t('admin.sectionCosts')}>
|
||||
<p className="max-w-2xl text-sm text-muted-foreground">{t('admin.costs.intro')}</p>
|
||||
<p className="text-sm text-muted-foreground">{t('admin.costs.intro')}</p>
|
||||
<ChoiceGroup
|
||||
label={t('admin.costs.period')}
|
||||
value={String(days) as `${Period}`}
|
||||
|
|
@ -47,8 +47,8 @@ export default function CostsPage() {
|
|||
</div>
|
||||
))}
|
||||
</dl>
|
||||
<p className="max-w-2xl text-sm text-muted-foreground">{t('admin.costs.estimate', { model: query.data.model })}</p>
|
||||
{query.data.unpriced && <p className="max-w-2xl text-sm text-muted-foreground">{t('admin.costs.unpriced')}</p>}
|
||||
<p className="text-sm text-muted-foreground">{t('admin.costs.estimate', { model: query.data.model })}</p>
|
||||
{query.data.unpriced && <p className="text-sm text-muted-foreground">{t('admin.costs.unpriced')}</p>}
|
||||
</section>
|
||||
|
||||
{query.data.daily.length === 0 ? (
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export default function JobsPage() {
|
|||
|
||||
return (
|
||||
<Section title={t('admin.sectionJobs')}>
|
||||
<p className="max-w-2xl text-sm text-muted-foreground">{t('admin.jobs.intro')}</p>
|
||||
<p className="text-sm text-muted-foreground">{t('admin.jobs.intro')}</p>
|
||||
<div className="flex flex-col gap-4">
|
||||
{JOBS.map((kind) => (
|
||||
<JobCard key={kind} kind={kind} enabled={enabled} />
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useUpdateProvider, type Provider } from '@/api/adminProviders'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import Confirm from './Confirm'
|
||||
import { errorText } from './errorText'
|
||||
import LidarrSetup from './LidarrSetup'
|
||||
|
|
@ -34,26 +34,12 @@ export default function ProviderCard({ provider }: { provider: Provider }) {
|
|||
return (
|
||||
<section aria-label={name} className="flex flex-col gap-4 rounded-xl bg-secondary p-5 text-secondary-foreground">
|
||||
<div className="flex flex-wrap items-center gap-4">
|
||||
<button
|
||||
type="button"
|
||||
role="switch"
|
||||
aria-checked={on}
|
||||
<Switch
|
||||
checked={on}
|
||||
aria-label={name}
|
||||
disabled={(missing !== null && !on) || update.isPending}
|
||||
onClick={() => (on ? update.mutate({ name: provider.name, enabled: false }) : setAsking(true))}
|
||||
className={cn(
|
||||
'relative h-7 w-12 shrink-0 rounded-md border border-input transition-colors focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring disabled:opacity-50',
|
||||
on ? 'bg-primary' : 'bg-secondary',
|
||||
)}
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className={cn(
|
||||
'absolute top-0.5 left-0.5 size-5 rounded-sm transition-transform motion-reduce:transition-none',
|
||||
on ? 'translate-x-5 bg-primary-foreground' : 'bg-muted-foreground',
|
||||
)}
|
||||
/>
|
||||
</button>
|
||||
/>
|
||||
<h3 className="text-xl font-bold">{name}</h3>
|
||||
<span className="text-sm text-muted-foreground">{t(on ? 'admin.providers.on' : 'admin.providers.off')}</span>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ export default function ProvidersPage() {
|
|||
|
||||
return (
|
||||
<Section title={t('admin.sectionProviders')}>
|
||||
<p className="max-w-2xl text-sm text-muted-foreground">{t('admin.providers.intro')}</p>
|
||||
<p className="text-sm text-muted-foreground">{t('admin.providers.intro')}</p>
|
||||
{providers.isError ? (
|
||||
<ErrorMessage error={providers.error} onRetry={() => void providers.refetch()} />
|
||||
) : providers.isPending ? (
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ export default function ScanPanel({ full, onFullChange }: { full: boolean; onFul
|
|||
<input type="checkbox" checked={full} onChange={(e) => onFullChange(e.target.checked)} className="size-5 accent-primary" />
|
||||
{t('admin.scan.full')}
|
||||
</label>
|
||||
<p className="max-w-xl text-sm text-muted-foreground">{t('admin.scan.fullHint')}</p>
|
||||
<p className="text-sm text-muted-foreground">{t('admin.scan.fullHint')}</p>
|
||||
<Button disabled={running || start.isPending} onClick={() => start.mutate({ full })}>
|
||||
{t('admin.scan.all')}
|
||||
</Button>
|
||||
|
|
|
|||
|
|
@ -1,23 +1,17 @@
|
|||
import type { ComponentType } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Navigate, type RouteObject } from 'react-router-dom'
|
||||
import RouteLoading from '@/components/RouteLoading'
|
||||
import Shell from '@/components/layout/Shell'
|
||||
import HomePage from '@/pages/HomePage'
|
||||
import NotFoundPage from '@/pages/NotFoundPage'
|
||||
|
||||
/** What is on screen while the first page of a lazy route is being fetched. */
|
||||
function Loading() {
|
||||
const { t } = useTranslation()
|
||||
return <div role="status" aria-label={t('common.loading')} className="min-h-screen bg-background" />
|
||||
}
|
||||
|
||||
/** A page that is fetched when somebody first opens it, so that the first screen does not carry the admin area. */
|
||||
const page = (load: () => Promise<{ default: ComponentType }>) => async () => ({ Component: (await load()).default })
|
||||
|
||||
export const routes: RouteObject[] = [
|
||||
{
|
||||
element: <Shell />,
|
||||
HydrateFallback: Loading,
|
||||
HydrateFallback: RouteLoading,
|
||||
children: [
|
||||
{ path: '/', element: <HomePage /> },
|
||||
{ path: '/search', lazy: page(() => import('@/pages/SearchPage')) },
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { readFileSync } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
import { describe, expect, test } from 'vitest'
|
||||
import { THEMES } from './theme'
|
||||
import { BAR_COLOURS, THEMES } from './theme'
|
||||
|
||||
// Vitest runs from web/. (import.meta.url is not a file URL under jsdom, and ?raw gives empty CSS.)
|
||||
const css = readFileSync(resolve(process.cwd(), 'src/theme/themes.css'), 'utf8')
|
||||
|
|
@ -56,3 +56,7 @@ describe.each(THEMES.map((t) => t.id))('theme %s', (id) => {
|
|||
expect(tokens['border']).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
||||
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'])
|
||||
})
|
||||
|
|
|
|||
|
|
@ -53,3 +53,15 @@ test('initTheme still works when reading storage throws', () => {
|
|||
expect(() => initTheme()).not.toThrow()
|
||||
expect(document.documentElement.dataset.theme).toBe('sonda')
|
||||
})
|
||||
|
||||
test('the colour of the browser bar follows the theme', () => {
|
||||
const meta = document.createElement('meta')
|
||||
meta.name = 'theme-color'
|
||||
meta.content = '#000000'
|
||||
document.head.append(meta)
|
||||
setTheme('gruvbox-light')
|
||||
expect(meta.content).toBe('#fbf1c7')
|
||||
setTheme('dracula')
|
||||
expect(meta.content).toBe('#282a36')
|
||||
meta.remove()
|
||||
})
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue