Compare commits

...

3 Commits

Author SHA1 Message Date
327885f968 Update Players and Games on connection check 2025-05-27 02:29:46 +02:00
1df2506b8c Add Player button 2025-05-27 02:22:53 +02:00
952d1804ad Proper Scale for Charts 2025-05-26 19:56:04 +02:00
3 changed files with 32 additions and 26 deletions

View File

@ -8,7 +8,7 @@ import {ApiUriContext, getData} from "./api/fetchApi.tsx";
import {GetGames, GetPlayers} from "./api/endpoints/Data.tsx"; import {GetGames, GetPlayers} from "./api/endpoints/Data.tsx";
import { import {
AccordionGroup, AccordionGroup,
Box, CircularProgress, Box, Button, CircularProgress,
Divider, Divider,
Input, Input,
Stack, Stack,
@ -19,6 +19,7 @@ import PlayerAccordionItem from "./components/PlayerAccordionItem.tsx";
import PlayerGameStatsDrawer from "./components/PlayerGameStatsDrawer.tsx"; import PlayerGameStatsDrawer from "./components/PlayerGameStatsDrawer.tsx";
import {Cancel, CheckCircleOutline} from '@mui/icons-material'; import {Cancel, CheckCircleOutline} from '@mui/icons-material';
import {PlayerStatsDrawer} from "./components/PlayerStatsDrawer.tsx"; import {PlayerStatsDrawer} from "./components/PlayerStatsDrawer.tsx";
import {AddPlayer} from "./api/endpoints/Actions.tsx";
export default function App() { export default function App() {
const [apiUri, setApiUri] = useState<string>("http://127.0.0.1:5239"); const [apiUri, setApiUri] = useState<string>("http://127.0.0.1:5239");
@ -44,26 +45,19 @@ export default function App() {
setOpenPlayerStats(true); setOpenPlayerStats(true);
} }
useEffect(() => {
if(!connected)
{
setPlayers([]);
setGames([]);
return;
}
GetPlayers(apiUri).then(setPlayers);
GetGames(apiUri).then(setGames);
}, [connected]);
const checkConnection = () => { const checkConnection = () => {
setCheckingConnection(true); setCheckingConnection(true);
return getData(`${apiUri}/swagger/v1/swagger.json`) return getData(`${apiUri}/swagger/v1/swagger.json`)
.then(() => { .then(() => {
setConnected(true); setConnected(true);
GetPlayers(apiUri).then(setPlayers);
GetGames(apiUri).then(setGames);
return Promise.resolve(); return Promise.resolve();
}) })
.catch(() => { .catch(() => {
setConnected(false) setConnected(false)
setPlayers([]);
setGames([]);
return Promise.reject(); return Promise.reject();
}) })
.finally(() => { .finally(() => {
@ -71,7 +65,6 @@ export default function App() {
}); });
} }
const [connectionTimer, setConnectionTimer] = useState<number | null>(null); const [connectionTimer, setConnectionTimer] = useState<number | null>(null);
useEffect(() => { useEffect(() => {
@ -81,21 +74,33 @@ export default function App() {
.then(() => setConnectionTimer(setInterval(checkConnection, 5000))); .then(() => setConnectionTimer(setInterval(checkConnection, 5000)));
}, [apiUri]); }, [apiUri]);
const [addPlayerStr, setAddPlayerStr] = useState("");
const addPlayer = () => {
const steamId = BigInt(addPlayerStr);
AddPlayer(apiUri, steamId);
}
return ( return (
<ApiUriContext value={apiUri}> <ApiUriContext value={apiUri}>
<PlayersContext.Provider value={{players: players}}> <PlayersContext.Provider value={{players: players}}>
<GamesContext value={{games: games}}> <GamesContext value={{games: games}}>
<Input type={"text"} <Stack direction="row" spacing={2} position={"fixed"} top={5}>
placeholder={"Api Uri"} <Input type={"text"}
value={apiUri} placeholder={"Api Uri"}
onChange={(e) => setApiUri(e.target.value)} value={apiUri}
endDecorator={checkingConnection onChange={(e) => setApiUri(e.target.value)}
? <CircularProgress sx={{height: "100%"}} /> endDecorator={checkingConnection
: connected ? <CircularProgress sx={{height: "100%"}} />
? <CheckCircleOutline color={"success"} /> : connected
: <Cancel color={"error"} />} ? <CheckCircleOutline color={"success"} />
/> : <Cancel color={"error"} />}
<Stack direction={"row"} spacing={2}> />
<Input type={"text"}
placeholder={"Add SteamId"}
onChange={(e) => setAddPlayerStr(e.target.value)}
endDecorator={<Button onClick={addPlayer}>Add</Button>}
/>
</Stack>
<Stack direction={"row"} spacing={2} overflow={"scroll"} position={"fixed"} top={50} width={"100%"} height={"calc(100% - 50px)"}>
<Box sx={{width:'50%'}}> <Box sx={{width:'50%'}}>
<Typography level={"h2"}>Players</Typography> <Typography level={"h2"}>Players</Typography>
<AccordionGroup> <AccordionGroup>

View File

@ -30,7 +30,8 @@ export default function PlayerGameStatsDrawer({player, game, open, setOpen} : {p
</DialogTitle> </DialogTitle>
<DialogContent> <DialogContent>
<LineChart xAxis={[{data : trackedTime?.map(t => new Date(t.timeStamp))??[], scaleType: "utc", label: "Date"}]} <LineChart xAxis={[{data : trackedTime?.map(t => new Date(t.timeStamp))??[], scaleType: "utc", label: "Date"}]}
series={[{data: trackedTime?.map(t => Number(t.timePlayed))??[], label: "Minutes Played"}]} yAxis={[{label: "Minutes Played", scaleType: "linear", min: 0}]}
series={[{data: trackedTime?.map(t => Number(t.timePlayed))??[], label: game?.name}]}
sx={{height: "80%"}}/> sx={{height: "80%"}}/>
</DialogContent> </DialogContent>
</Drawer> </Drawer>

View File

@ -78,7 +78,7 @@ export function PlayerStatsDrawer({player, open, setOpen}: {
/> />
<LineChart dataset={trackedTimes} <LineChart dataset={trackedTimes}
xAxis={[{dataKey: "date", scaleType: "utc"}]} xAxis={[{dataKey: "date", scaleType: "utc"}]}
yAxis={[{dataKey: "time", scaleType: "linear"}]} yAxis={[{dataKey: "time", scaleType: "linear", min: 0}]}
series={selectedSeries} series={selectedSeries}
/> />
</Stack> </Stack>