automatic rejoin on reload or server restart
This commit is contained in:
parent
feaf96c10e
commit
64a61ef2b3
1 changed files with 141 additions and 58 deletions
|
|
@ -1,12 +1,17 @@
|
|||
import { useEffect, useState } from 'react';
|
||||
import {useEffect, useState} from 'react';
|
||||
import './PlayerInfo.css'
|
||||
import { PlayerResponse, getPlayer } from './serverCalls';
|
||||
import {PlayerResponse, getPlayer} from './serverCalls';
|
||||
|
||||
export default function PlayerInfo({ playerId }: { playerId: string }) {
|
||||
export default function PlayerInfo({playerId, logout}: { playerId: string, logout: () => void }) {
|
||||
const [player, setPlayer] = useState<PlayerResponse | null>();
|
||||
|
||||
const refresh = () => {
|
||||
getPlayer(playerId).then(setPlayer);
|
||||
getPlayer(playerId).then(value => {
|
||||
if (value)
|
||||
setPlayer(value);
|
||||
else
|
||||
logout();
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -15,34 +20,34 @@ export default function PlayerInfo({ playerId }: { playerId: string }) {
|
|||
});
|
||||
|
||||
return <div className='TankWelcome'>
|
||||
<h1 className='Elems' style={{ "color": "white" }}>
|
||||
<h1 className='Elems' style={{"color": "white"}}>
|
||||
Tanks
|
||||
</h1>
|
||||
<div className="ScoreForm">
|
||||
<div className='ElemGroup'>
|
||||
<p className='Elems' style={{ "color": "white" }}>
|
||||
<p className='Elems' style={{"color": "white"}}>
|
||||
name:
|
||||
</p>
|
||||
<p className='Elems' style={{ "color": "white" }}>
|
||||
<p className='Elems' style={{"color": "white"}}>
|
||||
{player?.name}
|
||||
</p>
|
||||
</div>
|
||||
<div className='ElemGroup'>
|
||||
<p className='Elems' style={{ "color": "white" }}>
|
||||
<p className='Elems' style={{"color": "white"}}>
|
||||
kills:
|
||||
</p>
|
||||
<p className='Elems' style={{ "color": "white" }}>
|
||||
{player?.kills}
|
||||
<p className='Elems' style={{"color": "white"}}>
|
||||
{player?.scores.kills}
|
||||
</p>
|
||||
</div>
|
||||
<div className='ElemGroup'>
|
||||
<p className='Elems' style={{ "color": "white" }}>
|
||||
<p className='Elems' style={{"color": "white"}}>
|
||||
deaths:
|
||||
</p>
|
||||
<p className='Elems' style={{ "color": "white" }}>
|
||||
{player?.deaths}
|
||||
<p className='Elems' style={{"color": "white"}}>
|
||||
{player?.scores.deaths}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div >;
|
||||
</div>;
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue