Add the V2 web app: design system, shell, study flows, AI, settings, sharing

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Elijah 2026-11-11 08:53:01 -07:00
parent eae109c166
commit 74a98ac1f1
52 changed files with 11976 additions and 1 deletions

125
web/src/pages/Auth.tsx Normal file
View file

@ -0,0 +1,125 @@
import { useQueryClient } from '@tanstack/react-query';
import { KeyRound, LockKeyhole } from 'lucide-react';
import { useState, type FormEvent } from 'react';
import { api, errorMessage } from '@/lib/api';
import { qk } from '@/lib/queries';
import { useDocumentTitle } from '@/lib/util';
import { Button, Callout, Field, Input } from '@/ui';
export function Brand({ size = 'md' }: { size?: 'md' | 'lg' }) {
return (
<div className="flex items-center gap-2.5">
<img src="/icon.svg" alt="" className={size === 'lg' ? 'size-11 rounded-[12px]' : 'size-8 rounded-[9px]'} />
<span className={size === 'lg' ? 'display text-[28px]' : 'display text-[21px]'}>Study Desk</span>
</div>
);
}
function AuthFrame({ title, subtitle, children }: { title: string; subtitle: string; children: React.ReactNode }) {
return (
<main className="grid min-h-dvh place-items-center px-5 py-10">
<div className="w-full max-w-[400px] animate-in">
<div className="mb-8 flex justify-center">
<Brand size="lg" />
</div>
<div className="card p-6 sm:p-7">
<h1 className="display text-2xl">{title}</h1>
<p className="mt-1.5 mb-6 text-sm text-ink-2">{subtitle}</p>
{children}
</div>
</div>
</main>
);
}
export function LoginPage() {
useDocumentTitle('Sign in');
const qc = useQueryClient();
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const [busy, setBusy] = useState(false);
const submit = async (e: FormEvent) => {
e.preventDefault();
if (!password) return;
setBusy(true);
setError('');
try {
await api.post('/api/auth/login', { password });
qc.clear();
await qc.invalidateQueries({ queryKey: qk.auth });
} catch (err) {
setError(errorMessage(err));
setPassword('');
} finally {
setBusy(false);
}
};
return (
<AuthFrame title="Welcome back" subtitle="Enter your password to open your study desk.">
<form onSubmit={submit} className="space-y-4">
<Field label="Password" error={error || undefined}>
<Input type="password" autoFocus autoComplete="current-password" value={password} onChange={(e) => setPassword(e.target.value)} aria-invalid={Boolean(error)} />
</Field>
<Button type="submit" variant="primary" size="lg" block loading={busy} icon={<LockKeyhole />}>
Sign in
</Button>
</form>
</AuthFrame>
);
}
export function SetupPage() {
useDocumentTitle('Set up');
const qc = useQueryClient();
const [code, setCode] = useState('');
const [password, setPassword] = useState('');
const [confirm, setConfirm] = useState('');
const [error, setError] = useState('');
const [busy, setBusy] = useState(false);
const mismatch = confirm.length > 0 && password !== confirm;
const submit = async (e: FormEvent) => {
e.preventDefault();
if (password.length < 8) return setError('Use at least 8 characters.');
if (password !== confirm) return setError('The passwords do not match.');
setBusy(true);
setError('');
try {
await api.post('/api/auth/setup', { code, password });
await qc.invalidateQueries({ queryKey: qk.auth });
} catch (err) {
setError(errorMessage(err));
} finally {
setBusy(false);
}
};
return (
<AuthFrame title="Set up Study Desk" subtitle="Create the administrator password. You are the only account on this desk.">
<form onSubmit={submit} className="space-y-4">
<Callout tone="accent" icon={<KeyRound />}>
Find the one-time <strong>setup code</strong> in the container log, or in <code className="num text-[12px]">setup-code.txt</code> inside the data folder.
</Callout>
<Field label="Setup code">
<Input autoFocus value={code} onChange={(e) => setCode(e.target.value.toUpperCase())} placeholder="XXXXX-XXXXX" autoComplete="off" spellCheck={false} className="num tracking-widest" required />
</Field>
<Field label="Password" hint="At least 8 characters. A short sentence works well.">
<Input type="password" autoComplete="new-password" value={password} onChange={(e) => setPassword(e.target.value)} required minLength={8} />
</Field>
<Field label="Confirm password" error={mismatch ? 'The passwords do not match.' : undefined}>
<Input type="password" autoComplete="new-password" value={confirm} onChange={(e) => setConfirm(e.target.value)} required aria-invalid={mismatch} />
</Field>
{error && (
<Callout tone="bad" className="py-2.5">
{error}
</Callout>
)}
<Button type="submit" variant="primary" size="lg" block loading={busy}>
Create password and continue
</Button>
</form>
</AuthFrame>
);
}