Update Players and Games on connection check
This commit is contained in:
15
src/App.tsx
15
src/App.tsx
@ -45,26 +45,19 @@ export default function App() {
|
||||
setOpenPlayerStats(true);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if(!connected)
|
||||
{
|
||||
setPlayers([]);
|
||||
setGames([]);
|
||||
return;
|
||||
}
|
||||
GetPlayers(apiUri).then(setPlayers);
|
||||
GetGames(apiUri).then(setGames);
|
||||
}, [connected]);
|
||||
|
||||
const checkConnection = () => {
|
||||
setCheckingConnection(true);
|
||||
return getData(`${apiUri}/swagger/v1/swagger.json`)
|
||||
.then(() => {
|
||||
setConnected(true);
|
||||
GetPlayers(apiUri).then(setPlayers);
|
||||
GetGames(apiUri).then(setGames);
|
||||
return Promise.resolve();
|
||||
})
|
||||
.catch(() => {
|
||||
setConnected(false)
|
||||
setPlayers([]);
|
||||
setGames([]);
|
||||
return Promise.reject();
|
||||
})
|
||||
.finally(() => {
|
||||
|
Reference in New Issue
Block a user