-
Notifications
You must be signed in to change notification settings - Fork 5k
/
Copy pathAgents.tsx
47 lines (42 loc) · 1.37 KB
/
Agents.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { useQuery } from "@tanstack/react-query";
import { Button } from "@/components/ui/button";
import { useNavigate } from "react-router-dom";
import "./App.css";
type Agent = {
id: string;
name: string;
};
function Agents() {
const navigate = useNavigate();
const { data: agents, isLoading } = useQuery({
queryKey: ["agents"],
queryFn: async () => {
const res = await fetch("/api/agents");
const data = await res.json();
return data.agents as Agent[];
},
});
return (
<div className="min-h-screen flex flex-col items-center justify-center p-4">
<h1 className="text-2xl font-bold mb-8">Select your agent:</h1>
{isLoading ? (
<div>Loading agents...</div>
) : (
<div className="grid gap-4 w-full max-w-md">
{agents?.map((agent) => (
<Button
key={agent.id}
className="w-full text-lg py-6"
onClick={() => {
navigate(`/${agent.id}`);
}}
>
{agent.name}
</Button>
))}
</div>
)}
</div>
);
}
export default Agents;