sonda/web/src/components/layout/Shell.tsx
tgiachi 75a7898c68 feat(web): make Sonda feel like an app on a phone
A review of the phone experience (the issue) found a desktop page made
smaller. What changes:

feat:
- The player bar is one row on a phone (cover, title, play and next, a thin
  line of progress) and is not there while nothing plays. A tap or a swipe up
  on it opens the full-screen player.
- The Back gesture closes the full-screen player instead of leaving the page
  under it; a swipe down closes it too. The full queue is listed on a phone.
- The queue is kept in the browser: a reload, or a tab that Android throws
  away, comes back paused on the same song at the same second. It belongs to
  the person signed in and is forgotten on sign-out.
- Tabs have icons; the page starts at its top on a new route and back goes to
  where the list was; a swipe on the page no longer reloads it.

fix:
- The player now knows when the system pauses the audio (another app, a
  headset), so the button and the lock screen no longer say it plays.
- The lock screen has a working seek bar and the right play/pause state.
- The player bar was not hidden by max-sm:hidden: its grid rules were outside
  the Tailwind layers and won. They are in the components layer now.
- Song rows give the title the room on a phone (no number column).
- The album header is centred and the greeting is smaller on a phone; recent
  songs on Home show the artist.
- Thumbnails ask for the small cover (300 px) and not the 1000 px one.
- Pages use dvh, the viewport covers the notch, and the tabs keep clear of
  the gesture bar; the update notice no longer sits on the bar.
- No grey tap flash, no double-tap delay, no image menu on a long press.
2026-11-16 17:38:58 +01:00

61 lines
2.4 KiB
TypeScript

import { useRef } from 'react'
import { useTranslation } from 'react-i18next'
import { Outlet, ScrollRestoration, useLocation } from 'react-router-dom'
import SearchBox from '@/components/SearchBox'
import { useRadioRefill } from '@/player/radio'
import { usePlayerEngine } from '@/player/usePlayer'
import UpdateNotice from '@/pwa/UpdateNotice'
import PhoneTabs from './PhoneTabs'
import PlayerBar from './PlayerBar'
import Sidebar from './Sidebar'
import { useBackClosesPlayer } from './useBackClosesPlayer'
/** The frame of the app: the sidebar, the page, and the player bar. */
export default function Shell() {
const { t } = useTranslation()
const main = useRef<HTMLElement>(null)
// The search page has its own box, and a phone has the Search tab.
const searching = useLocation().pathname.startsWith('/search')
usePlayerEngine()
useRadioRefill()
useBackClosesPlayer()
return (
<div className="flex min-h-dvh flex-col bg-background text-foreground">
{/* The first stop of the Tab key: it jumps over the sidebar. It moves the focus itself, so the address does not change. */}
<a
href="#main"
onClick={(e) => {
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')}
</a>
<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] px-5 py-6 outline-none sm:px-14 sm:py-11"
>
{!searching && (
<div className="sticky top-0 z-20 -mx-14 -mt-11 mb-8 bg-background px-14 py-3 max-sm:hidden">
<SearchBox />
</div>
)}
<Outlet />
</main>
</div>
{/* Sticky here, not on the bar: a sticky element only sticks inside its parent. */}
<div className="sticky bottom-0 z-10">
<PlayerBar />
<PhoneTabs />
</div>
<UpdateNotice />
{/* A new page starts at its top, and back goes to where the list was. */}
<ScrollRestoration />
</div>
)
}