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/NowPlaying.tsx b/web/src/components/layout/NowPlaying.tsx index 8015b21..85fe160 100644 --- a/web/src/components/layout/NowPlaying.tsx +++ b/web/src/components/layout/NowPlaying.tsx @@ -16,19 +16,36 @@ import PlayerControls from './PlayerControls' const UP_NEXT = 3 +/** The big seek bar and the times. The part of this screen that follows the playback every moment. */ +function NowPlayingSeek({ durationMs }: { durationMs: number }) { + const positionMs = usePlayer((s) => s.positionMs) + const seek = usePlayer((s) => s.seek) + return ( +
+ +
+ {formatTime(positionMs)} + {formatTime(durationMs)} +
+
+ ) +} + /** The full-screen player: a big cover, the controls and what comes next. */ export default function NowPlaying() { const { t } = useTranslation() const { open, setOpen } = useNowPlayingUi() - const player = usePlayer() - const track = currentTrack(player) + const track = usePlayer(currentTrack) + const queue = usePlayer((s) => s.queue) + const index = usePlayer((s) => s.index) + const jumpTo = usePlayer((s) => s.jumpTo) // Nothing left to show (the queue was emptied): close. useEffect(() => { if (open && !track) setOpen(false) }, [open, track, setOpen]) - const upNext = player.queue.slice(player.index + 1, player.index + 1 + UP_NEXT) + const upNext = queue.slice(index + 1, index + 1 + UP_NEXT) return ( @@ -79,18 +96,7 @@ export default function NowPlaying() { )}
-
- -
- {formatTime(player.positionMs)} - {formatTime(track.duration_ms)} -
-
+ @@ -102,8 +108,8 @@ export default function NowPlaying() { player.jumpTo(player.index + 1 + k)} + index={index + 1 + k} + onPlay={() => jumpTo(index + 1 + k)} /> ))} diff --git a/web/src/components/layout/Player.test.tsx b/web/src/components/layout/Player.test.tsx index 141ff21..2adfc89 100644 --- a/web/src/components/layout/Player.test.tsx +++ b/web/src/components/layout/Player.test.tsx @@ -1,3 +1,4 @@ +import { Profiler } from 'react' import { act, fireEvent, render, screen, within } from '@testing-library/react' import userEvent from '@testing-library/user-event' import { MemoryRouter } from 'react-router-dom' @@ -11,6 +12,7 @@ import { usePlayer } from '@/player/store' import { useNowPlayingUi } from '@/player/ui' import { fakeFullscreen } from '@/test/fullscreen' import PlayerBar from './PlayerBar' +import PlayerControls from './PlayerControls' function track(n: number, over: Partial = {}): Track { return { @@ -303,3 +305,24 @@ test('Tab stays inside the full-screen player', async () => { for (const el of outside) if (el) expect(el.contains(document.activeElement)).toBe(false) } }) + +test('the controls and the title do not render again when only the position moves', () => { + usePlayer.getState().playTracks([a, b], 0) + let commits = 0 + render( + + commits++}> + + + , + ) + const before = commits + act(() => usePlayer.getState().tick(5_000)) + 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/layout/PlayerBar.tsx b/web/src/components/layout/PlayerBar.tsx index d56926b..010c61b 100644 --- a/web/src/components/layout/PlayerBar.tsx +++ b/web/src/components/layout/PlayerBar.tsx @@ -2,6 +2,7 @@ import { ListMusic } from 'lucide-react' import { useEffect } from 'react' import { useTranslation } from 'react-i18next' import { Link } from 'react-router-dom' +import type { Track } from '@/api/catalog' import Cover from '@/components/Cover' import FullscreenButton from '@/components/FullscreenButton' import Scrubber from '@/components/Scrubber' @@ -28,12 +29,26 @@ function usePlayPauseKey() { }, []) } +/** The position, the seek bar and the length. The only part of the bar that follows the playback every moment. */ +function PlayerSeek({ track }: { track: Track | null }) { + const positionMs = usePlayer((s) => s.positionMs) + const seek = usePlayer((s) => s.seek) + return ( +
+ {formatTime(track ? positionMs : 0)} +
+ +
+ {formatTime(track?.duration_ms ?? 0)} +
+ ) +} + /** The bar at the bottom of every page: what is playing, the controls and the position. */ export default function PlayerBar() { const { t } = useTranslation() - const player = usePlayer() const setOpen = useNowPlayingUi((s) => s.setOpen) - const track = currentTrack(player) + const track = usePlayer(currentTrack) usePlayPauseKey() return ( @@ -74,18 +89,7 @@ export default function PlayerBar() {
-
- {formatTime(track ? player.positionMs : 0)} -
- -
- {formatTime(track?.duration_ms ?? 0)} -
+
diff --git a/web/src/components/layout/PlayerControls.tsx b/web/src/components/layout/PlayerControls.tsx index 9ece9b1..3105a3c 100644 --- a/web/src/components/layout/PlayerControls.tsx +++ b/web/src/components/layout/PlayerControls.tsx @@ -7,45 +7,52 @@ import { currentTrack, usePlayer } from '@/player/store' /** Shuffle, previous, play/pause, next and repeat. Used by the player bar and the full-screen player. */ export default function PlayerControls({ large = false }: { large?: boolean }) { const { t } = useTranslation() - const player = usePlayer() - const none = currentTrack(player) === null + const none = usePlayer((s) => currentTrack(s) === null) + const playing = usePlayer((s) => s.playing) + const shuffle = usePlayer((s) => s.shuffle) + const repeat = usePlayer((s) => s.repeat) + const toggleShuffle = usePlayer((s) => s.toggleShuffle) + const prev = usePlayer((s) => s.prev) + const togglePlay = usePlayer((s) => s.togglePlay) + const next = usePlayer((s) => s.next) + const cycleRepeat = usePlayer((s) => s.cycleRepeat) const small = large ? 'size-12' : 'size-11' - const repeatLabel = { off: 'player.repeatOff', all: 'player.repeatAll', one: 'player.repeatOne' }[player.repeat] + const repeatLabel = { off: 'player.repeatOff', all: 'player.repeatAll', one: 'player.repeatOne' }[repeat] return (
- -
) diff --git a/web/src/components/layout/Shell.test.tsx b/web/src/components/layout/Shell.test.tsx index 75c95f6..21192ba 100644 --- a/web/src/components/layout/Shell.test.tsx +++ b/web/src/components/layout/Shell.test.tsx @@ -1,5 +1,6 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query' -import { render, screen, within } from '@testing-library/react' +import { render, screen, waitFor, within } from '@testing-library/react' +import userEvent from '@testing-library/user-event' import { createMemoryRouter, RouterProvider } from 'react-router-dom' import { beforeEach, expect, test, vi } from 'vitest' import { sessionStore } from '@/auth/session' @@ -12,21 +13,24 @@ beforeEach(async () => { await initI18n() }) -function renderAt(path: string) { +async function renderAt(path: string) { const router = createMemoryRouter(routes, { initialEntries: [path] }) render( , ) + // The pages are fetched when first opened: wait until the one asked for is in. + await waitFor(() => expect(router.state.initialized).toBe(true)) + await screen.findByRole('main') } function mainNav() { return screen.getByRole('navigation', { name: 'Main' }) } -test('at /artists the Artists link is the current page and the others are not', () => { - renderAt('/artists') +test('at /artists the Artists link is the current page and the others are not', async () => { + await renderAt('/artists') const nav = within(mainNav()) expect(nav.getByRole('link', { name: 'Artists' })).toHaveAttribute('aria-current', 'page') for (const name of ['Home', 'Search', 'Discover', 'Albums', 'Songs', 'Settings']) { @@ -39,16 +43,16 @@ const adminRoutes = { 'GET /api/v1/library/scan': () => ({ running: false }), } -test('an admin has an Admin link, and a user who is not one has none', () => { +test('an admin has an Admin link, and a user who is not one has none', async () => { sessionStore.setState({ status: 'authenticated', user: { id: 1, email: 'tom@example.org', is_admin: false } }) - renderAt('/artists') + await renderAt('/artists') expect(within(mainNav()).queryByRole('link', { name: 'Admin' })).not.toBeInTheDocument() }) test('the Admin link opens the libraries and stays current inside the admin area', async () => { sessionStore.setState({ status: 'authenticated', user: { id: 1, email: 'tom@example.org', is_admin: true } }) mockFetch(adminRoutes) - renderAt('/admin') + await renderAt('/admin') expect(await screen.findByRole('region', { name: 'Libraries' })).toBeInTheDocument() expect(within(mainNav()).getByRole('link', { name: 'Admin' })).toHaveAttribute('aria-current', 'page') }) @@ -56,7 +60,7 @@ test('the Admin link opens the libraries and stays current inside the admin area test('the admin area has a Users section next to Libraries', async () => { sessionStore.setState({ status: 'authenticated', user: { id: 1, email: 'tom@example.org', is_admin: true } }) mockFetch({ ...adminRoutes, 'GET /api/v1/users': () => ({ users: [{ id: 1, email: 'tom@example.org', is_admin: true }] }) }) - renderAt('/admin/users') + await renderAt('/admin/users') expect(await screen.findByRole('region', { name: 'Users' })).toBeInTheDocument() const sections = within(screen.getByRole('navigation', { name: 'Admin sections' })) expect(sections.getByRole('link', { name: 'Users' })).toHaveAttribute('aria-current', 'page') @@ -66,7 +70,7 @@ test('the admin area has a Users section next to Libraries', async () => { test('the admin area has a Providers section too', async () => { sessionStore.setState({ status: 'authenticated', user: { id: 1, email: 'tom@example.org', is_admin: true } }) mockFetch({ ...adminRoutes, 'GET /api/v1/providers': () => ({ providers: [] }) }) - renderAt('/admin/providers') + await renderAt('/admin/providers') expect(await screen.findByRole('region', { name: 'Providers' })).toBeInTheDocument() expect(within(screen.getByRole('navigation', { name: 'Admin sections' })).getByRole('link', { name: 'Providers' })).toHaveAttribute('aria-current', 'page') }) @@ -80,7 +84,7 @@ test('the admin area has a Jobs section too', async () => { 'GET /api/v1/library/artist-images': () => ({ running: false }), 'GET /api/v1/library/descriptions': () => ({ running: false }), }) - renderAt('/admin/jobs') + await renderAt('/admin/jobs') expect(await screen.findByRole('region', { name: 'Jobs' })).toBeInTheDocument() expect(within(screen.getByRole('navigation', { name: 'Admin sections' })).getByRole('link', { name: 'Jobs' })).toHaveAttribute('aria-current', 'page') }) @@ -88,8 +92,8 @@ test('the admin area has a Jobs section too', async () => { test('someone who is not an admin who opens the jobs address gets a notice and no request', async () => { sessionStore.setState({ status: 'authenticated', user: { id: 2, email: 'ann@example.org', is_admin: false } }) const { calls } = mockFetch({ 'GET /api/v1/library/covers': () => ({ running: false }) }) - renderAt('/admin/jobs') - expect(screen.getByText('Only admins can see this page.')).toBeInTheDocument() + await renderAt('/admin/jobs') + expect(await screen.findByText('Only admins can see this page.')).toBeInTheDocument() await new Promise((r) => setTimeout(r, 30)) expect(calls).toHaveLength(0) }) @@ -97,8 +101,8 @@ test('someone who is not an admin who opens the jobs address gets a notice and n test('someone who is not an admin who opens the providers address gets a notice and no request', async () => { sessionStore.setState({ status: 'authenticated', user: { id: 2, email: 'ann@example.org', is_admin: false } }) const { calls } = mockFetch({ 'GET /api/v1/providers': () => ({ providers: [] }) }) - renderAt('/admin/providers') - expect(screen.getByText('Only admins can see this page.')).toBeInTheDocument() + await renderAt('/admin/providers') + expect(await screen.findByText('Only admins can see this page.')).toBeInTheDocument() await new Promise((r) => setTimeout(r, 30)) expect(calls).toHaveLength(0) }) @@ -106,8 +110,8 @@ test('someone who is not an admin who opens the providers address gets a notice test('someone who is not an admin who opens the users address gets a notice and no request', async () => { sessionStore.setState({ status: 'authenticated', user: { id: 2, email: 'ann@example.org', is_admin: false } }) const { calls } = mockFetch({ 'GET /api/v1/users': () => ({ users: [] }) }) - renderAt('/admin/users') - expect(screen.getByText('Only admins can see this page.')).toBeInTheDocument() + await renderAt('/admin/users') + expect(await screen.findByText('Only admins can see this page.')).toBeInTheDocument() await new Promise((r) => setTimeout(r, 30)) expect(calls).toHaveLength(0) }) @@ -115,30 +119,30 @@ test('someone who is not an admin who opens the users address gets a notice and test('someone who is not an admin who opens the admin address gets a notice and no request', async () => { sessionStore.setState({ status: 'authenticated', user: { id: 2, email: 'ann@example.org', is_admin: false } }) const { calls } = mockFetch(adminRoutes) - renderAt('/admin/libraries') - expect(screen.getByText('Only admins can see this page.')).toBeInTheDocument() + await renderAt('/admin/libraries') + expect(await screen.findByText('Only admins can see this page.')).toBeInTheDocument() await new Promise((r) => setTimeout(r, 30)) expect(calls.filter((c) => c.url.pathname.includes('librar'))).toHaveLength(0) }) -test('Home is the current page only on /', () => { - renderAt('/') +test('Home is the current page only on /', async () => { + await renderAt('/') expect(within(mainNav()).getByRole('link', { name: 'Home' })).toHaveAttribute('aria-current', 'page') }) -test('an artist page keeps the Artists link current', () => { - renderAt('/artists/5') +test('an artist page keeps the Artists link current', async () => { + await renderAt('/artists/5') expect(within(mainNav()).getByRole('link', { name: 'Artists' })).toHaveAttribute('aria-current', 'page') }) -test('the page has one main landmark and says what the server does with data', () => { - renderAt('/songs') +test('the page has one main landmark and says what the server does with data', async () => { + await renderAt('/songs') expect(screen.getAllByRole('main')).toHaveLength(1) expect(screen.getByText('Nothing leaves this server unless an admin turns a provider on.')).toBeInTheDocument() }) -test('the home page opens with a greeting as its heading', () => { - renderAt('/') +test('the home page opens with a greeting as its heading', async () => { + await renderAt('/') expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent(/^Good (morning|afternoon|evening)$/) }) @@ -149,19 +153,29 @@ test.each([ ['/songs', 'Songs'], ['/discover', 'Discover'], ['/settings', 'Settings'], -])('the route %s opens a page headed %s', (path, heading) => { - renderAt(path) +])('the route %s opens a page headed %s', async (path, heading) => { + await renderAt(path) expect(screen.getByRole('heading', { level: 1, name: heading })).toBeInTheDocument() }) -test.each(['/artists/5', '/albums/5'])('the detail route %s opens inside the shell and starts loading', (path) => { +test.each(['/artists/5', '/albums/5'])('the detail route %s opens inside the shell and starts loading', async (path) => { mockFetch({}) - renderAt(path) + await renderAt(path) expect(within(screen.getByRole('main')).getByRole('status')).toHaveTextContent('Loading') }) -test('an unknown path shows the not-found page with a way back', () => { - renderAt('/no/such/page') +test('an unknown path shows the not-found page with a way back', async () => { + await renderAt('/no/such/page') expect(screen.getByRole('heading', { name: 'This page does not exist' })).toBeInTheDocument() expect(screen.getByRole('link', { name: 'Back to Home' })).toHaveAttribute('href', '/') }) + +test('a skip link comes first and moves the focus to the page', async () => { + const user = userEvent.setup() + await renderAt('/artists') + await user.tab() + const skip = screen.getByRole('link', { name: 'Skip to content' }) + expect(skip).toHaveFocus() + await user.keyboard('{Enter}') + expect(screen.getByRole('main')).toHaveFocus() +}) diff --git a/web/src/components/layout/Shell.tsx b/web/src/components/layout/Shell.tsx index df9b2c1..691424f 100644 --- a/web/src/components/layout/Shell.tsx +++ b/web/src/components/layout/Shell.tsx @@ -1,3 +1,5 @@ +import { useRef } from 'react' +import { useTranslation } from 'react-i18next' import { Outlet } from 'react-router-dom' import { usePlayerEngine } from '@/player/usePlayer' import UpdateNotice from '@/pwa/UpdateNotice' @@ -6,12 +8,30 @@ import Sidebar from './Sidebar' /** The frame of the app: the sidebar, the page, and the player bar. */ export default function Shell() { + const { t } = useTranslation() + const main = useRef(null) usePlayerEngine() return (
+ {/* The first stop of the Tab key: it jumps over the sidebar. It moves the focus itself, so the address does not change. */} + { + e.preventDefault() + main.current?.focus() + }} + className="sr-only focus-visible:not-sr-only focus-visible:fixed focus-visible:top-2 focus-visible:left-2 focus-visible:z-50 focus-visible:rounded-md focus-visible:bg-primary focus-visible:px-4 focus-visible:py-2 focus-visible:font-bold focus-visible:text-primary-foreground" + > + {t('app.skip')} +
-
+
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/i18n/locales/en.json b/web/src/i18n/locales/en.json index df8248c..cc914cd 100644 --- a/web/src/i18n/locales/en.json +++ b/web/src/i18n/locales/en.json @@ -1,6 +1,7 @@ { "app": { "name": "Sonda", + "skip": "Skip to content", "privacy": "Nothing leaves this server unless an admin turns a provider on." }, "nav": { diff --git a/web/src/i18n/locales/it.json b/web/src/i18n/locales/it.json index a699824..50f0eb2 100644 --- a/web/src/i18n/locales/it.json +++ b/web/src/i18n/locales/it.json @@ -1,6 +1,7 @@ { "app": { "name": "Sonda", + "skip": "Vai al contenuto", "privacy": "Niente esce da questo server finché un admin non accende un provider." }, "nav": { 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 2b86df4..9eb01bf 100644 --- a/web/src/router.tsx +++ b/web/src/router.tsx @@ -1,62 +1,46 @@ +import type { ComponentType } from 'react' import { Navigate, type RouteObject } from 'react-router-dom' +import RouteLoading from '@/components/RouteLoading' import Shell from '@/components/layout/Shell' -import AlbumPage from '@/pages/AlbumPage' -import AlbumsPage from '@/pages/AlbumsPage' -import ArtistPage from '@/pages/ArtistPage' -import ArtistsPage from '@/pages/ArtistsPage' -import DiscoverPage from '@/pages/DiscoverPage' import HomePage from '@/pages/HomePage' -import MixesPage from '@/pages/MixesPage' -import MixPage from '@/pages/MixPage' -import AdminLayout from '@/pages/admin/AdminLayout' -import CostsPage from '@/pages/admin/CostsPage' -import JobsPage from '@/pages/admin/JobsPage' -import LibrariesPage from '@/pages/admin/LibrariesPage' -import ProvidersPage from '@/pages/admin/ProvidersPage' -import UsersPage from '@/pages/admin/UsersPage' import NotFoundPage from '@/pages/NotFoundPage' -import PlaylistPage from '@/pages/PlaylistPage' -import PlaylistsPage from '@/pages/PlaylistsPage' -import SearchPage from '@/pages/SearchPage' -import SmartEditorPage from '@/pages/SmartEditorPage' -import SmartPlaylistPage from '@/pages/SmartPlaylistPage' -import SmartPlaylistsPage from '@/pages/SmartPlaylistsPage' -import SettingsPage from '@/pages/SettingsPage' -import SongsPage from '@/pages/SongsPage' -import SuggestedSmartPage from '@/pages/SuggestedSmartPage' + +/** 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: RouteLoading, children: [ { path: '/', element: }, - { path: '/search', element: }, - { path: '/discover', element: }, - { path: '/artists', element: }, - { path: '/artists/:id', element: }, - { path: '/albums', element: }, - { path: '/albums/:id', element: }, - { path: '/songs', element: }, - { path: '/mixes', element: }, - { path: '/mixes/:id', element: }, - { path: '/playlists', element: }, - { path: '/playlists/:id', element: }, - { path: '/smart-playlists', element: }, - { path: '/smart-playlists/new', element: }, - { path: '/smart-playlists/suggested/:key', element: }, - { path: '/smart-playlists/:id', element: }, - { path: '/smart-playlists/:id/edit', element: }, - { path: '/settings', element: }, + { path: '/search', lazy: page(() => import('@/pages/SearchPage')) }, + { path: '/discover', lazy: page(() => import('@/pages/DiscoverPage')) }, + { path: '/artists', lazy: page(() => import('@/pages/ArtistsPage')) }, + { path: '/artists/:id', lazy: page(() => import('@/pages/ArtistPage')) }, + { path: '/albums', lazy: page(() => import('@/pages/AlbumsPage')) }, + { path: '/albums/:id', lazy: page(() => import('@/pages/AlbumPage')) }, + { path: '/songs', lazy: page(() => import('@/pages/SongsPage')) }, + { path: '/mixes', lazy: page(() => import('@/pages/MixesPage')) }, + { path: '/mixes/:id', lazy: page(() => import('@/pages/MixPage')) }, + { path: '/playlists', lazy: page(() => import('@/pages/PlaylistsPage')) }, + { path: '/playlists/:id', lazy: page(() => import('@/pages/PlaylistPage')) }, + { path: '/smart-playlists', lazy: page(() => import('@/pages/SmartPlaylistsPage')) }, + { path: '/smart-playlists/new', lazy: page(() => import('@/pages/SmartEditorPage')) }, + { path: '/smart-playlists/suggested/:key', lazy: page(() => import('@/pages/SuggestedSmartPage')) }, + { path: '/smart-playlists/:id', lazy: page(() => import('@/pages/SmartPlaylistPage')) }, + { path: '/smart-playlists/:id/edit', lazy: page(() => import('@/pages/SmartEditorPage')) }, + { path: '/settings', lazy: page(() => import('@/pages/SettingsPage')) }, { path: '/admin', - element: , + lazy: page(() => import('@/pages/admin/AdminLayout')), children: [ { index: true, element: }, - { path: 'libraries', element: }, - { path: 'users', element: }, - { path: 'providers', element: }, - { path: 'jobs', element: }, - { path: 'costs', element: }, + { path: 'libraries', lazy: page(() => import('@/pages/admin/LibrariesPage')) }, + { path: 'users', lazy: page(() => import('@/pages/admin/UsersPage')) }, + { path: 'providers', lazy: page(() => import('@/pages/admin/ProvidersPage')) }, + { path: 'jobs', lazy: page(() => import('@/pages/admin/JobsPage')) }, + { path: 'costs', lazy: page(() => import('@/pages/admin/CostsPage')) }, ], }, { path: '*', element: }, 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()) }