sonda/web/src/auth/LoginPage.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

84 lines
2.9 KiB
TypeScript

import { useState, type FormEvent } from 'react'
import { useTranslation } from 'react-i18next'
import { ApiError } from '@/api/client'
import Logo from '@/components/Logo'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { errorMessageKey } from '@/i18n'
import { login, register } from './session'
/** Sign in, or (on a new server) create the first account, which becomes the admin. */
export default function LoginPage() {
const { t } = useTranslation()
const [creating, setCreating] = useState(false)
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const [error, setError] = useState<string | null>(null)
const [busy, setBusy] = useState(false)
async function submit(event: FormEvent) {
event.preventDefault()
setBusy(true)
setError(null)
try {
await (creating ? register : login)(email, password)
} catch (e) {
setError(t(errorMessageKey(e instanceof ApiError ? e.code : 'unknown')))
} finally {
setBusy(false)
}
}
return (
<main className="flex min-h-dvh items-center justify-center bg-background p-4">
<div className="flex w-full max-w-sm flex-col gap-6 rounded-xl bg-card p-8 text-card-foreground">
<Logo name={t('app.name')} className="h-9 w-auto self-start" />
<h1 className="text-xl font-bold">{creating ? t('auth.registerTitle') : t('auth.signInTitle')}</h1>
<form onSubmit={submit} className="flex flex-col gap-4">
<div className="flex flex-col gap-2">
<Label htmlFor="email">{t('auth.email')}</Label>
<Input
id="email"
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
autoComplete="email"
required
/>
</div>
<div className="flex flex-col gap-2">
<Label htmlFor="password">{t('auth.password')}</Label>
<Input
id="password"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
autoComplete={creating ? 'new-password' : 'current-password'}
required
/>
</div>
{error && (
<p role="alert" className="text-sm text-destructive">
{error}
</p>
)}
<Button type="submit" disabled={busy}>
{creating ? t('auth.createAccount') : t('auth.signIn')}
</Button>
</form>
<Button
type="button"
variant="link"
className="min-h-11 self-start px-0"
onClick={() => {
setCreating(!creating)
setError(null)
}}
>
{creating ? t('auth.haveAccount') : t('auth.firstUser')}
</Button>
</div>
</main>
)
}