From c91831594f3886f7a5a336e901b03f9b7ac8e7f9 Mon Sep 17 00:00:00 2001 From: glax Date: Mon, 26 May 2025 17:41:15 +0200 Subject: [PATCH] SteamId, AppId --- src/components/GameAccordionItem.tsx | 23 ++++++++++++++----- src/components/PlayerAccordionItem.tsx | 31 +++++++++++++++++++++----- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/components/GameAccordionItem.tsx b/src/components/GameAccordionItem.tsx index 1e0f351..5300a61 100644 --- a/src/components/GameAccordionItem.tsx +++ b/src/components/GameAccordionItem.tsx @@ -2,8 +2,8 @@ import type IGame from "../api/types/IGame.ts"; import { Accordion, AccordionDetails, - AccordionSummary, - Stack, Typography + AccordionSummary, CircularProgress, + Stack, Tooltip, Typography } from "@mui/joy"; import type IPlayer from "../api/types/IPlayer.ts"; import {useContext, useEffect, useState} from "react"; @@ -16,19 +16,30 @@ export default function GameAccordionItem({game, OpenDrawer} : {game: IGame, Ope const [players, setPlayers] = useState([]); const [expanded, setExpanded] = useState(false); + const [loading, setLoading] = useState(false); useEffect(() => { if(!expanded) return; - GetPlayersOfGame(apiUri, game.appId).then(setPlayers); + setLoading(true); + GetPlayersOfGame(apiUri, game.appId) + .then(setPlayers) + .finally(() => setLoading(false)); }, [expanded]); return ( setExpanded(expanded)}> - {game.name} + + + + {game.name} + + - - {players?.map((player) => OpenDrawer(player, game)} />)} + + {loading + ? + : players?.map((player) => OpenDrawer(player, game)} />)} diff --git a/src/components/PlayerAccordionItem.tsx b/src/components/PlayerAccordionItem.tsx index c1c4b0d..3550817 100644 --- a/src/components/PlayerAccordionItem.tsx +++ b/src/components/PlayerAccordionItem.tsx @@ -2,33 +2,52 @@ import type IGame from "../api/types/IGame.ts"; import { Accordion, AccordionDetails, - AccordionSummary, - Stack, Typography + AccordionSummary, Button, CircularProgress, + Stack, Tooltip, Typography } from "@mui/joy"; import type IPlayer from "../api/types/IPlayer.ts"; import {useContext, useEffect, useState} from "react"; import {ApiUriContext} from "../api/fetchApi.tsx"; import {GetGamesOfPlayer} from "../api/endpoints/Data.tsx"; import GameCard from "./GameCard.tsx"; +import {GetTotal} from "../api/endpoints/TimeTrack.tsx"; export default function PlayerAccordionItem({player, OpenDrawer} : {player: IPlayer, OpenDrawer : (player: IPlayer, game: IGame) => void}) { const apiUri = useContext(ApiUriContext); const [games, setGames] = useState([]); const [expanded, setExpanded] = useState(false); + const [loadingGames, setLoadingGames] = useState(false); + const [totalTime, setTotalTime] = useState(BigInt(0)); useEffect(() => { if(!expanded) return; - GetGamesOfPlayer(apiUri, player.steamId).then(setGames); + setLoadingGames(true); + GetGamesOfPlayer(apiUri, player.steamId) + .then(setGames) + .finally(() => setLoadingGames(false)); + GetTotal(apiUri, player.steamId) + .then(setTotalTime) }, [expanded]); return ( setExpanded(expanded)}> - {player.name} + + + + {player.name} + + - - {games?.map((game) => OpenDrawer(player, game)} />)} + + + Total Time: {totalTime} + + + {loadingGames + ? + : games?.map((game) => OpenDrawer(player, game)} />)}