import { useCallback, useEffect, useState } from 'react'; import { api } from '../api/api'; import { ApiError } from '../api/http'; import type { City } from '../api/types'; import { useAuth } from '../auth/AuthContext'; import { useToast } from '../components/Toast'; import { formatMoney, riskLabel } from '../shared/format'; export function TravelScreen() { const { player, setPlayer } = useAuth(); const { toast } = useToast(); const [cities, setCities] = useState([]); const [busy, setBusy] = useState(false); const reload = useCallback(async () => { const res = await api.cities(); setCities(res.cities); }, []); useEffect(() => { void reload(); }, [reload]); async function travelTo(city: City) { setBusy(true); try { const res = await api.travel(city.id); setPlayer(res.player); toast(`Benvenuto a ${res.cityName} (−${formatMoney(res.cost)})`, 'success'); } catch (err) { toast(err instanceof ApiError ? err.message : 'Errore imprevisto', 'error'); } finally { setBusy(false); } } return (

Città

); }