diff --git a/web/src/components/ListeningSwitch.tsx b/web/src/components/ListeningSwitch.tsx index 8e30b29..b5df309 100644 --- a/web/src/components/ListeningSwitch.tsx +++ b/web/src/components/ListeningSwitch.tsx @@ -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 (
- + /> {t('discover.listening.label')} diff --git a/web/src/components/RouteLoading.tsx b/web/src/components/RouteLoading.tsx new file mode 100644 index 0000000..39ba75c --- /dev/null +++ b/web/src/components/RouteLoading.tsx @@ -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
+} diff --git a/web/src/components/Scrubber.tsx b/web/src/components/Scrubber.tsx index fef02c0..96d4370 100644 --- a/web/src/components/Scrubber.tsx +++ b/web/src/components/Scrubber.tsx @@ -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', )} /> ) diff --git a/web/src/components/layout/Player.test.tsx b/web/src/components/layout/Player.test.tsx index 56bdf3f..2adfc89 100644 --- a/web/src/components/layout/Player.test.tsx +++ b/web/src/components/layout/Player.test.tsx @@ -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( {}} variant="line" />) + expect(screen.getByRole('slider')).toHaveClass('h-11') +}) diff --git a/web/src/components/ui/switch.test.tsx b/web/src/components/ui/switch.test.tsx new file mode 100644 index 0000000..1544bbf --- /dev/null +++ b/web/src/components/ui/switch.test.tsx @@ -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() + 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() + const sw = screen.getByRole('switch') + expect(sw).toHaveClass('h-11') + expect(sw).toHaveAttribute('aria-checked', 'true') + await userEvent.click(sw) + expect(onClick).not.toHaveBeenCalled() +}) diff --git a/web/src/components/ui/switch.tsx b/web/src/components/ui/switch.tsx new file mode 100644 index 0000000..016ce15 --- /dev/null +++ b/web/src/components/ui/switch.tsx @@ -0,0 +1,37 @@ +import type { ComponentProps } from 'react' +import { cn } from '@/lib/utils' + +interface SwitchProps extends Omit, '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 ( + + ) +} diff --git a/web/src/index.css b/web/src/index.css index 770ca55..115c2aa 100644 --- a/web/src/index.css +++ b/web/src/index.css @@ -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; } diff --git a/web/src/pages/MixPage.tsx b/web/src/pages/MixPage.tsx index d00be23..6108174 100644 --- a/web/src/pages/MixPage.tsx +++ b/web/src/pages/MixPage.tsx @@ -44,7 +44,7 @@ function MixView({ id }: { id: string }) {

{title}

- {mix.artists.length > 0 &&

{t('mixes.with', { artists: mix.artists.join(', ') })}

} + {mix.artists.length > 0 &&

{t('mixes.with', { artists: mix.artists.join(', ') })}

}

{t('playlists.meta', { count: mix.tracks.length, duration: formatTime(duration) })}

diff --git a/web/src/pages/SmartPlaylistPage.tsx b/web/src/pages/SmartPlaylistPage.tsx index d17c677..420d1bf 100644 --- a/web/src/pages/SmartPlaylistPage.tsx +++ b/web/src/pages/SmartPlaylistPage.tsx @@ -56,7 +56,7 @@ function SmartView({ id }: { id: number }) {

{p.name}

- {p.description &&

{p.description}

} + {p.description &&

{p.description}

}
    {describeRules(t, p.rules).map((line) => (
  • diff --git a/web/src/pages/SuggestedSmartPage.tsx b/web/src/pages/SuggestedSmartPage.tsx index a8cfa16..80b7e91 100644 --- a/web/src/pages/SuggestedSmartPage.tsx +++ b/web/src/pages/SuggestedSmartPage.tsx @@ -55,7 +55,7 @@ function SuggestedView({ name: key }: { name: string }) {

    {title}

    -

    {description}

    +

    {description}

      {describeRules(t, suggested.rules).map((line) => (
    • diff --git a/web/src/pages/admin/CostsPage.tsx b/web/src/pages/admin/CostsPage.tsx index 65ede06..d3bb1c1 100644 --- a/web/src/pages/admin/CostsPage.tsx +++ b/web/src/pages/admin/CostsPage.tsx @@ -16,7 +16,7 @@ export default function CostsPage() { return (
      -

      {t('admin.costs.intro')}

      +

      {t('admin.costs.intro')}

      ))} -

      {t('admin.costs.estimate', { model: query.data.model })}

      - {query.data.unpriced &&

      {t('admin.costs.unpriced')}

      } +

      {t('admin.costs.estimate', { model: query.data.model })}

      + {query.data.unpriced &&

      {t('admin.costs.unpriced')}

      }
      {query.data.daily.length === 0 ? ( diff --git a/web/src/pages/admin/JobsPage.tsx b/web/src/pages/admin/JobsPage.tsx index b5754dd..93e775f 100644 --- a/web/src/pages/admin/JobsPage.tsx +++ b/web/src/pages/admin/JobsPage.tsx @@ -17,7 +17,7 @@ export default function JobsPage() { return (
      -

      {t('admin.jobs.intro')}

      +

      {t('admin.jobs.intro')}

      {JOBS.map((kind) => ( diff --git a/web/src/pages/admin/ProviderCard.tsx b/web/src/pages/admin/ProviderCard.tsx index 01d8334..0a7f203 100644 --- a/web/src/pages/admin/ProviderCard.tsx +++ b/web/src/pages/admin/ProviderCard.tsx @@ -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 (
      - + />

      {name}

      {t(on ? 'admin.providers.on' : 'admin.providers.off')}
      diff --git a/web/src/pages/admin/ProvidersPage.tsx b/web/src/pages/admin/ProvidersPage.tsx index 7cfcfa4..fe3b8f8 100644 --- a/web/src/pages/admin/ProvidersPage.tsx +++ b/web/src/pages/admin/ProvidersPage.tsx @@ -11,7 +11,7 @@ export default function ProvidersPage() { return (
      -

      {t('admin.providers.intro')}

      +

      {t('admin.providers.intro')}

      {providers.isError ? ( void providers.refetch()} /> ) : providers.isPending ? ( diff --git a/web/src/pages/admin/ScanPanel.tsx b/web/src/pages/admin/ScanPanel.tsx index 1989d50..8509729 100644 --- a/web/src/pages/admin/ScanPanel.tsx +++ b/web/src/pages/admin/ScanPanel.tsx @@ -56,7 +56,7 @@ export default function ScanPanel({ full, onFullChange }: { full: boolean; onFul onFullChange(e.target.checked)} className="size-5 accent-primary" /> {t('admin.scan.full')} -

      {t('admin.scan.fullHint')}

      +

      {t('admin.scan.fullHint')}

      diff --git a/web/src/router.tsx b/web/src/router.tsx index bf01d2e..9eb01bf 100644 --- a/web/src/router.tsx +++ b/web/src/router.tsx @@ -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
      -} - /** 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: , - HydrateFallback: Loading, + HydrateFallback: RouteLoading, children: [ { path: '/', element: }, { path: '/search', lazy: page(() => import('@/pages/SearchPage')) }, diff --git a/web/src/theme/contrast.test.ts b/web/src/theme/contrast.test.ts index 5f0eb96..3e2b255 100644 --- a/web/src/theme/contrast.test.ts +++ b/web/src/theme/contrast.test.ts @@ -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']) +}) diff --git a/web/src/theme/theme.test.ts b/web/src/theme/theme.test.ts index a369b76..19d3eeb 100644 --- a/web/src/theme/theme.test.ts +++ b/web/src/theme/theme.test.ts @@ -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() +}) diff --git a/web/src/theme/theme.ts b/web/src/theme/theme.ts index 9f9c2d8..de707c6 100644 --- a/web/src/theme/theme.ts +++ b/web/src/theme/theme.ts @@ -11,6 +11,16 @@ export const THEMES: readonly { id: ThemeId; labelKey: string }[] = [ { id: 'neon', labelKey: 'theme.neon' }, ] +/** 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 = { + sonda: '#0a1218', + 'tokyo-night': '#1a1b26', + 'gruvbox-dark': '#282828', + 'gruvbox-light': '#fbf1c7', + dracula: '#282a36', + neon: '#14073d', +} + const KEY = 'sonda.theme' const DEFAULT: ThemeId = 'sonda' @@ -32,6 +42,7 @@ function readStored(): string | null { function apply(id: ThemeId) { current = id document.documentElement.dataset.theme = id + document.querySelector('meta[name="theme-color"]')?.setAttribute('content', BAR_COLOURS[id]) listeners.forEach((fn) => fn()) }