21});
22
23// HTTP vals expect an exported "fetch handler"
24// This is how you "run the server" in Val Town with Hono
25export default app.fetch;
87 const [currentGame, setCurrentGame] = useState<Game | null>(null);
88
89 // Fetch players on component mount
90 useEffect(() => {
91 fetchPlayers();
92 }, []);
93
111 }, [gameState?.currentPlayerIndex, gameState?.currentCard?.id]);
112
113 // Fetch players from the API
114 const fetchPlayers = async () => {
115 try {
116 setLoading(true);
117 const response = await fetch("/api/players");
118 if (!response.ok) {
119 throw new Error("Failed to fetch players");
120 }
121 const data = await response.json();
138 const deletePlayer = async (id: string) => {
139 try {
140 const response = await fetch(`/api/players/${id}`, {
141 method: "DELETE",
142 });
182
183 try {
184 // Fetch a card from the selected card set
185 const response = await fetch(`/api/card-sets/${cardSet.id}/cards`);
186 if (!response.ok) {
187 throw new Error("Failed to fetch cards");
188 }
189
207 }
208 } catch (err) {
209 console.error("Error fetching cards:", err);
210 setError("Failed to load cards. Please try again.");
211 }
87 const [currentGame, setCurrentGame] = useState<Game | null>(null);
88
89 // Fetch players on component mount
90 useEffect(() => {
91 fetchPlayers();
92 }, []);
93
111 }, [gameState?.currentPlayerIndex, gameState?.currentCard?.id]);
112
113 // Fetch players from the API
114 const fetchPlayers = async () => {
115 try {
116 setLoading(true);
117 const response = await fetch("/api/players");
118 if (!response.ok) {
119 throw new Error("Failed to fetch players");
120 }
121 const data = await response.json();
138 const deletePlayer = async (id: string) => {
139 try {
140 const response = await fetch(`/api/players/${id}`, {
141 method: "DELETE",
142 });
182
183 try {
184 // Fetch a card from the selected card set
185 const response = await fetch(`/api/card-sets/${cardSet.id}/cards`);
186 if (!response.ok) {
187 throw new Error("Failed to fetch cards");
188 }
189
207 }
208 } catch (err) {
209 console.error("Error fetching cards:", err);
210 setError("Failed to load cards. Please try again.");
211 }
442
443// Export the app for Val Town
444export default app.fetch;
37
38 try {
39 const response = await fetch("/api/players", {
40 method: "POST",
41 headers: {
29
30 try {
31 const response = await fetch("/api/games", {
32 method: "POST",
33 headers: {
790
791// Export the app for Val Town
792export default app.fetch;
15 const [showNewGameForm, setShowNewGameForm] = useState(false);
16
17 // Fetch games on component mount
18 useEffect(() => {
19 fetchGames();
20 }, []);
21
22 // Fetch games from the API
23 const fetchGames = async () => {
24 try {
25 setLoading(true);
26 const response = await fetch("/api/games");
27 if (!response.ok) {
28 throw new Error("Failed to fetch games");
29 }
30 const data = await response.json();
49 const handleDeleteGame = async (id: string) => {
50 try {
51 const response = await fetch(`/api/games/${id}`, {
52 method: "DELETE",
53 });
18 const [error, setError] = useState<string | null>(null);
19
20 // Fetch game and players on component mount
21 useEffect(() => {
22 fetchGame();
23 fetchPlayers();
24 }, [gameId]);
25
26 // Fetch game from the API
27 const fetchGame = async () => {
28 try {
29 setLoading(true);
30 const response = await fetch(`/api/games/${gameId}`);
31 if (!response.ok) {
32 throw new Error("Failed to fetch game");
33 }
34 const data = await response.json();
43 };
44
45 // Fetch players for this game from the API
46 const fetchPlayers = async () => {
47 try {
48 setLoading(true);
49 const response = await fetch(`/api/games/${gameId}/players`);
50 if (!response.ok) {
51 throw new Error("Failed to fetch players");
52 }
53 const data = await response.json();
75 const deletePlayer = async (id: string) => {
76 try {
77 const response = await fetch(`/api/games/${gameId}/players/${id}`, {
78 method: "DELETE",
79 });
29
30 try {
31 const response = await fetch("/api/games", {
32 method: "POST",
33 headers: {