// web/src/components/LoginScreen.tsx import React, { useState } from "react"; import { Button } from "./ui/button"; import { Input } from "./ui/input"; import { Label } from "./ui/label"; import { Card } from "./ui/card"; import clareAvatar from "../assets/dfe44dab3ad8cd93953eac4a3e68bd1a5f999653.png"; import type { User } from "../App"; import { apiLogin } from "../lib/api"; interface LoginScreenProps { onLogin: (user: User) => void; } export function LoginScreen({ onLogin }: LoginScreenProps) { const [showForm, setShowForm] = useState(false); const [name, setName] = useState(""); const [email, setEmail] = useState(""); const [submitting, setSubmitting] = useState(false); const [err, setErr] = useState(null); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setErr(null); const n = name.trim(); const u = email.trim(); if (!n || !u) return; setSubmitting(true); try { // backend expects: { name, user_id } const resp = await apiLogin({ name: n, user_id: u }); // api.ts returns { ok: true/false ... } if ((resp as any)?.ok !== true) { const msg = (resp as any)?.error || "Login failed"; setErr(msg); return; } onLogin({ name: n, email: u }); } catch (e: any) { setErr(e?.message || "Login failed"); } finally { setSubmitting(false); } }; return (
Clare AI

Welcome to Clare

Your AI teaching assistant for personalized learning

{!showForm ? ( ) : (
setName(e.target.value)} placeholder="Enter your name" required disabled={submitting} />
setEmail(e.target.value)} placeholder="Enter your email or ID" required disabled={submitting} />
{err && (
{err}
)}
)}
); }