From 7ccfb9a52cc78a95a4533ab4b971d959bdeecc1c Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Fri, 4 Jul 2025 22:37:36 -0700 Subject: add score json upload functionality --- frontend/src/pages/Home.tsx | 93 +++++++++++++++++++++++++++++++++------------ 1 file changed, 69 insertions(+), 24 deletions(-) (limited to 'frontend/src/pages/Home.tsx') diff --git a/frontend/src/pages/Home.tsx b/frontend/src/pages/Home.tsx index e42a2b8..0ee6862 100644 --- a/frontend/src/pages/Home.tsx +++ b/frontend/src/pages/Home.tsx @@ -1,8 +1,14 @@ import { Link, useNavigate } from 'react-router'; import { useAuth } from '../contexts/AuthContext'; +import type { SupportedGame } from '../types/game'; +import { useState, useEffect } from 'react'; + +import dancerushImage from '../assets/games/dancerush.webp'; const Home = () => { const { user, isLoading, logout } = useAuth(); + const [supportedGames, setSupportedGames] = useState([]); + const [gamesLoading, setGamesLoading] = useState(true); const navigate = useNavigate(); const handleLogout = async () => { @@ -15,7 +21,37 @@ const Home = () => { } }; - if (isLoading) { + const getGameImage = (internalName: string) => { + switch(internalName){ + case "dancerush": { + return dancerushImage; + } + default: { + return null + } + } + } + + useEffect(() => { + const fetchSupportedGames = async () => { + try { + const response = await fetch(import.meta.env.VITE_API_URL+'/supportedGames'); + if (!response.ok) { + throw new Error('Failed to fetch supported games'); + } + const data = await response.json(); + setSupportedGames(data); + } catch (error) { + console.error('Failed to fetch supported games:', error); + alert('Failed to load supported games. Please refresh the page.'); + } finally { + setGamesLoading(false); + } + }; + fetchSupportedGames(); + }, []); + + if (isLoading || gamesLoading) { return (
@@ -92,31 +128,40 @@ const Home = () => {

Track your rhythm game progress and performance

- {/* Coming Soon Card */} -
-
- - - -
-

Dashboard Coming Soon

-

- We're working hard to bring you an amazing dashboard experience. Track your scores, - analyze your performance, and compete with friends - all coming soon! -

-
-
-

- User ID: {user.id} -

-
-
-

- Email: {user.email} -

-
+ {/* Supported Games */} +
+
+ {supportedGames.map((game) => ( +
+
+ {getGameImage(game.internalName) !== null ? ( + {game.formattedName} + ) : ( +
+
+ + + +
+
+ )} +
+
+

{game.formattedName}

+

{game.description}

+
+
+ ))}
+
); -- cgit v1.2.3