wip scores, components
This commit is contained in:
parent
64a61ef2b3
commit
b604c01e22
1 changed files with 250 additions and 115 deletions
|
|
@ -1,53 +1,46 @@
|
|||
import {useEffect, useState} from 'react';
|
||||
import './PlayerInfo.css'
|
||||
import {PlayerResponse, getPlayer} from './serverCalls';
|
||||
import {Guid} from "./Guid.ts";
|
||||
import Column from "./components/Column.tsx";
|
||||
import Row from "./components/Row.tsx";
|
||||
import Button from "./components/Button.tsx";
|
||||
|
||||
export default function PlayerInfo({playerId, logout}: { playerId: string, logout: () => void }) {
|
||||
export default function PlayerInfo({playerId, logout, reset}: {
|
||||
playerId: Guid,
|
||||
logout: () => void,
|
||||
reset: () => void
|
||||
}) {
|
||||
const [player, setPlayer] = useState<PlayerResponse | null>();
|
||||
|
||||
const refresh = () => {
|
||||
getPlayer(playerId).then(value => {
|
||||
if (value)
|
||||
setPlayer(value);
|
||||
else
|
||||
logout();
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const refresh = () => {
|
||||
getPlayer(playerId).then(value => {
|
||||
if (value)
|
||||
setPlayer(value);
|
||||
else
|
||||
logout();
|
||||
});
|
||||
};
|
||||
|
||||
const timer = setInterval(refresh, 5000);
|
||||
return () => clearInterval(timer);
|
||||
});
|
||||
}, [playerId]);
|
||||
|
||||
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>;
|
||||
return <Column className='PlayerInfo'>
|
||||
<Row>
|
||||
<h3 className='grow'>
|
||||
{player ? `Playing as "${player?.name}"` : 'loading...'}
|
||||
</h3>
|
||||
<Button className='PlayerInfo-Reset' onClick={() => reset()} text='x'/>
|
||||
</Row>
|
||||
<Row>
|
||||
<p className='Elems'> kills: </p>
|
||||
<p className='Elems'>{player?.scores.kills}</p>
|
||||
</Row>
|
||||
<Row>
|
||||
<p className='Elems'>deaths: </p>
|
||||
<p className='Elems'>{player?.scores.deaths}</p>
|
||||
</Row>
|
||||
</Column>;
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue