src/components/Sports.tsx
import { useEffect, useState } from 'react';
import { insforge } from '../lib/insforge';
interface Sport {
id: string;
name: string;
}
export function Sports() {
const [sports, setSports] = useState<Sport[]>([]);
const [error, setError] = useState<string | null>(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
async function fetchSports() {
const { data, error } = await insforge.database
.from('sports')
.select();
if (error) {
setError(error.message);
} else {
setSports(data || []);
}
setLoading(false);
}
fetchSports();
}, []);
if (loading) {
return (
<div className="min-h-screen flex items-center justify-center">
<p className="text-gray-600">Loading...</p>
</div>
);
}
if (error) {
return (
<div className="min-h-screen flex items-center justify-center">
<div className="text-red-600">
<h1 className="text-2xl font-bold mb-2">Error</h1>
<p>{error}</p>
</div>
</div>
);
}
return (
<div className="min-h-screen p-8">
<div className="max-w-4xl mx-auto">
<h1 className="text-4xl font-bold mb-8">Sports</h1>
{sports.length > 0 ? (
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
{sports.map((sport) => (
<div
key={sport.id}
className="p-6 bg-white rounded-lg shadow-md border border-gray-200 hover:shadow-lg transition-shadow"
>
<h2 className="text-xl font-semibold text-gray-800 capitalize">
{sport.name}
</h2>
<p className="text-sm text-gray-500 mt-2">ID: {sport.id}</p>
</div>
))}
</div>
) : (
<p className="text-gray-600">No sports found.</p>
)}
</div>
</div>
);
}