This repository has been archived on 2026-07-13. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
servicepoint-tanks/tank-frontend/src/PlayerInfo.tsx
2024-04-13 19:50:37 +02:00

53 lines
1.7 KiB
TypeScript

import {useEffect, useState} from 'react';
import './PlayerInfo.css'
import {PlayerResponse, getPlayer} from './serverCalls';
export default function PlayerInfo({playerId, logout}: { playerId: string, logout: () => void }) {
const [player, setPlayer] = useState<PlayerResponse | null>();
const refresh = () => {
getPlayer(playerId).then(value => {
if (value)
setPlayer(value);
else
logout();
});
};
useEffect(() => {
const timer = setInterval(refresh, 5000);
return () => clearInterval(timer);
});
return <div className='TankWelcome'>
<h1 className='Elems' style={{"color": "white"}}>
Tanks
</h1>
<div className="ScoreForm">
<div className='ElemGroup'>
<p className='Elems' style={{"color": "white"}}>
name:
</p>
<p className='Elems' style={{"color": "white"}}>
{player?.name}
</p>
</div>
<div className='ElemGroup'>
<p className='Elems' style={{"color": "white"}}>
kills:
</p>
<p className='Elems' style={{"color": "white"}}>
{player?.scores.kills}
</p>
</div>
<div className='ElemGroup'>
<p className='Elems' style={{"color": "white"}}>
deaths:
</p>
<p className='Elems' style={{"color": "white"}}>
{player?.scores.deaths}
</p>
</div>
</div>
</div>;
}