import { useState } from 'react' import type { Profile } from '../hooks/useAuth' import { type Gender, randomName } from '../lib/names' type Props = { onLoginSent: () => void onGuestLogin: (token: string, profile: Profile) => void } const GENDER_OPTIONS: { value: Gender; label: string; icon: string }[] = [ { value: 'male', label: 'Male', icon: '♂' }, { value: 'female', label: 'Female', icon: '♀' }, { value: 'mystery', label: 'Mystery', icon: '✦' }, ] export function LoginPage({ onLoginSent, onGuestLogin }: Props) { const [gender, setGender] = useState(null) const [name, setName] = useState('') const [joining, setJoining] = useState(false) const [showEmail, setShowEmail] = useState(false) const [email, setEmail] = useState('') const [submitting, setSubmitting] = useState(false) const [error, setError] = useState(null) function pickGender(g: Gender) { setGender(g) setName(randomName(g)) setError(null) } function reroll() { if (gender) setName(randomName(gender)) } async function startPlaying() { if (!name) return setJoining(true) setError(null) try { const r = await fetch('/api/auth/guest', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ display_name: name }), }) if (!r.ok) throw new Error('Failed to create session') const { token, profile } = await r.json() onGuestLogin(token, profile) } catch { setError('Something went wrong. Try again.') setJoining(false) } } async function sendMagicLink(e: React.FormEvent) { e.preventDefault() if (!email.includes('@') || !email.includes('.')) { setError('Enter a valid email address.') return } setSubmitting(true) setError(null) try { const r = await fetch('/api/auth/request', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email }), }) if (!r.ok) throw new Error('Failed to send link') onLoginSent() } catch { setError('Failed to send magic link. Try again.') } finally { setSubmitting(false) } } return (

Join the Telegraph Corps

No sign-up needed — pick your operator and start transmitting!

{/* Step 1: Gender picker */}

Choose your operator type:

{GENDER_OPTIONS.map(opt => ( ))}
{/* Step 2: Name + reroll + start */} {gender && (

Your operator name:

{name}
)} {error && (

{error}

)} {/* Optional email section */}
{showEmail && (

Enter your email to receive a magic link.

{ setEmail(e.target.value); setError(null) }} placeholder="telegraph@example.com" disabled={submitting} style={{ marginBottom: '0.5rem' }} />
)}
) }