import { useEffect, useState } from 'react'
import { api } from './lib/api'
type Connection = 'checking' | 'connected' | 'unavailable'
const connectionMessages: Record<Connection, string> = {
checking: 'Connecting to the backend…',
connected: 'Backend connected ✓',
unavailable: 'Backend unavailable',
}
const foundations = [
'Rust + Axum backend',
'React + TypeScript frontend',
'Vite development environment',
'/api routing and development proxy',
'Production frontend serving',
]
export default function App() {
const [connection, setConnection] = useState<Connection>('checking')
useEffect(() => {
const controller = new AbortController()
api.get('/api/health', { signal: controller.signal })
.then((health) => {
setConnection(health.status === 'ok' ? 'connected' : 'unavailable')
})
.catch(() => {
if (!controller.signal.aborted) setConnection('unavailable')
})
return () => controller.abort()
}, [])
return (
<main className="welcome">
<header className="welcome-heading">
<img className="logo" src="/capy.svg" alt="Capy" width="120" height="52" />
<h1>Your Capy app is ready.</h1>
<p>A calmer way to build web apps in Rust.</p>
</header>
<section className="setup-card" aria-labelledby="setup-title">
<div className="connection" data-state={connection} role="status" aria-atomic="true">
<span className="status-dot" aria-hidden="true" />
<div>
<p className="connection-title">{connectionMessages[connection]}</p>
<p className="connection-detail">
{connection === 'connected'
? 'Your frontend and backend are talking.'
: connection === 'checking'
? 'Making sure everything is connected.'
: 'Start your backend, then refresh to reconnect.'}
</p>
</div>
</div>
<div className="foundations">
<h2 id="setup-title">You’re ready to build.</h2>
<p>Capy has already wired together the foundations of your application:</p>
<ul>
{foundations.map((foundation) => (
<li key={foundation}>
<span className="feature-check" aria-hidden="true">✓</span>
{foundation}
</li>
))}
</ul>
</div>
<nav className="actions" aria-label="Get started">
<a className="button button-primary" href="https://docs.rs/capy-framework" target="_blank" rel="noreferrer">
Read the docs <span aria-hidden="true">↗</span>
<span className="sr-only"> (opens in a new tab)</span>
</a>
<a className="button button-secondary" href="/api/health">
View API <span aria-hidden="true">→</span>
</a>
</nav>
</section>
<footer className="welcome-footer">
<p>Let’s build something cool.</p>
<span>Your stack is ready. The interesting part starts now.</span>
</footer>
</main>
)
}