import { Ionicons } from '@expo/vector-icons'; import { router } from 'expo-router'; import { useCallback, useEffect, useState } from 'react'; import { ActivityIndicator, StyleSheet, View } from 'react-native'; import { AppHeader, AppText, Button, Card, FormField, IconButton, InlineBanner, Screen, colors, radius, spacing, } from '@/components/ui'; import { collegeApi, type Profile } from '@/lib/api'; export default function AccountScreen() { const [profile, setProfile] = useState(null); const [loading, setLoading] = useState(true); const [loadError, setLoadError] = useState(''); const [editing, setEditing] = useState(false); const [name, setName] = useState(''); const [college, setCollege] = useState(''); const [programme, setProgramme] = useState(''); const [semester, setSemester] = useState(''); const [saving, setSaving] = useState(false); const [formError, setFormError] = useState(''); const load = useCallback(() => { setLoading(true); setLoadError(''); collegeApi.profile() .then((result) => { setProfile(result); setName(result.name); setCollege(result.college); setProgramme(result.programme); setSemester(result.semester); }) .catch((error: Error) => setLoadError(error.message)) .finally(() => setLoading(false)); }, []); useEffect(() => { load(); }, [load]); const save = async () => { if (!name.trim() || !college.trim()) { setFormError('Your name and college are required.'); return; } setSaving(true); setFormError(''); try { const updated = await collegeApi.updateProfile({ name, college, programme, semester }); setProfile(updated); setEditing(false); } catch (error) { setFormError(error instanceof Error ? error.message : 'Please try again.'); } finally { setSaving(false); } }; return router.back()} />} trailing={profile ? { setEditing((value) => !value); setFormError(''); }} /> : undefined} /> {loading ? Loading profile… : null} {loadError ? } style={styles.error} /> : null} {profile ? <> {profile.initials || '?'} {profile.name} {profile.college} {editing ? Profile details {formError ? : null}