MCPcopy
hub / github.com/agentheroes/agentheroes / CharactersPage

Function CharactersPage

apps/frontend/src/components/character/page.tsx:23–268  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21}
22
23export function CharactersPage() {
24 const [characters, setCharacters] = useState<Character[]>([]);
25 const [loading, setLoading] = useState(true);
26 const [deleteConfirm, setDeleteConfirm] = useState<string | null>(null);
27 const fetch = useFetch();
28 const { toast } = useToast();
29
30 const loadCharacters = async () => {
31 try {
32 setLoading(true);
33 const response = await fetch("/characters");
34 if (response.ok) {
35 const data = await response.json();
36 setCharacters(data);
37 } else {
38 toast({
39 title: "Error",
40 description: "Failed to load characters",
41 variant: "destructive",
42 });
43 }
44 } catch (error) {
45 console.error("Error loading characters:", error);
46 toast({
47 title: "Error",
48 description: "Failed to load characters",
49 variant: "destructive",
50 });
51 } finally {
52 setLoading(false);
53 }
54 };
55
56 const handleDelete = async (id: string) => {
57 if (deleteConfirm !== id) {
58 // First click - ask for confirmation
59 setDeleteConfirm(id);
60 return;
61 }
62
63 try {
64 const response = await fetch(`/characters/${id}`, {
65 method: "DELETE",
66 });
67
68 if (response.ok) {
69 toast({
70 title: "Success",
71 description: "Character deleted successfully",
72 });
73 // Refresh the character list
74 loadCharacters();
75 } else {
76 toast({
77 title: "Error",
78 description: "Failed to delete character",
79 variant: "destructive",
80 });

Callers

nothing calls this directly

Calls 5

useFetchFunction · 0.90
useToastFunction · 0.90
getStatusInfoFunction · 0.85
loadCharactersFunction · 0.70
handleDeleteFunction · 0.70

Tested by

no test coverage detected