From 0d370b5a5dc33aae1bf571e147f7746e2bf3c54e Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Wed, 8 Oct 2025 17:07:52 -0700 Subject: frontend: pull formatted name for game on personal scores page --- frontend/README.md | 54 -------------------------------------------- frontend/src/pages/Score.tsx | 19 +++++++++++++++- 2 files changed, 18 insertions(+), 55 deletions(-) delete mode 100644 frontend/README.md diff --git a/frontend/README.md b/frontend/README.md deleted file mode 100644 index da98444..0000000 --- a/frontend/README.md +++ /dev/null @@ -1,54 +0,0 @@ -# React + TypeScript + Vite - -This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. - -Currently, two official plugins are available: - -- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh -- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh - -## Expanding the ESLint configuration - -If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules: - -```js -export default tseslint.config({ - extends: [ - // Remove ...tseslint.configs.recommended and replace with this - ...tseslint.configs.recommendedTypeChecked, - // Alternatively, use this for stricter rules - ...tseslint.configs.strictTypeChecked, - // Optionally, add this for stylistic rules - ...tseslint.configs.stylisticTypeChecked, - ], - languageOptions: { - // other options... - parserOptions: { - project: ['./tsconfig.node.json', './tsconfig.app.json'], - tsconfigRootDir: import.meta.dirname, - }, - }, -}) -``` - -You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules: - -```js -// eslint.config.js -import reactX from 'eslint-plugin-react-x' -import reactDom from 'eslint-plugin-react-dom' - -export default tseslint.config({ - plugins: { - // Add the react-x and react-dom plugins - 'react-x': reactX, - 'react-dom': reactDom, - }, - rules: { - // other rules... - // Enable its recommended typescript rules - ...reactX.configs['recommended-typescript'].rules, - ...reactDom.configs.recommended.rules, - }, -}) -``` diff --git a/frontend/src/pages/Score.tsx b/frontend/src/pages/Score.tsx index 5214f5b..ae2c794 100644 --- a/frontend/src/pages/Score.tsx +++ b/frontend/src/pages/Score.tsx @@ -2,6 +2,7 @@ import { useEffect, useState, useCallback } from "react"; import { useAuth } from "../contexts/AuthContext"; import { useNavigate } from "react-router"; import { NavBar } from "../components/NavBar"; +import type { SupportedGame} from "../types/game"; import SessionExpiredPopup from "../components/SessionExpiredPopup"; import ScoreDisplay from "../components/displays/GenericScoreDisplay"; import DancerushScoreDisplay from "../components/displays/DancerushScoreDisplay"; @@ -14,6 +15,7 @@ import { getFilterOptions } from "../types/constants"; const Score = () => { const { user, isLoading, logout } = useAuth(); const navigate = useNavigate(); + const [formattedGameName, setFormattedGameName] = useState(""); // eslint-disable-next-line @typescript-eslint/no-explicit-any const [scores, setScores] = useState([]); const [loading, setLoading] = useState(true); @@ -37,6 +39,21 @@ const Score = () => { } }; + useEffect(() => { + try{ + fetch(import.meta.env.VITE_API_URL + `/supportedGames`) + .then(response => response.json()) + .then(data => { + const game = data.find((game: SupportedGame) => game.internalName === gameName); + setFormattedGameName(game ? game.formattedName : gameName); + }) + .catch(error => console.error(error)); + } catch (error) { + console.error("Error:", error); + alert("Network error. Please try again."); + } + }, [gameName]); + const renderRequestFilterMenu = () => { const filterOptions = getFilterOptions(gameName); return ( @@ -158,7 +175,7 @@ const Score = () => {

- Your Scores + Your Scores for {formattedGameName}