Fixed loading issue

This commit is contained in:
Liam 2022-10-19 11:03:42 +01:00
parent 22bd73c142
commit d052178da0

@ -14,6 +14,7 @@ export default class Overlay extends Component {
super(props); super(props);
this.state = { this.state = {
loading: true, loading: true,
loadingPlayerData: true,
isConnectedToSocket: false, isConnectedToSocket: false,
id: undefined, id: undefined,
isValidSteamId: false, isValidSteamId: false,
@ -136,6 +137,8 @@ export default class Overlay extends Component {
if (this.state.isConnectedToSocket) return; if (this.state.isConnectedToSocket) return;
this.connectSocket(params.socketaddress); this.connectSocket(params.socketaddress);
} }
this.setState({ loading: false });
} }
/** /**
@ -158,10 +161,15 @@ export default class Overlay extends Component {
const json = await data.json(); const json = await data.json();
if (json.errorMessage) { if (json.errorMessage) {
// Invalid account // Invalid account
this.setState({ loading: false, isValidSteamId: false }); this.setState({ loadingPlayerData: false, isValidSteamId: false });
return; return;
} }
this.setState({ loading: false, id: id, data: json, isValidSteamId: true }); this.setState({
loadingPlayerData: false,
id: id,
data: json,
isValidSteamId: true,
});
} }
/** /**
@ -356,7 +364,14 @@ export default class Overlay extends Component {
}; };
render() { render() {
const { loading, isValidSteamId, data, websiteType } = this.state; const {
loading,
isValidSteamId,
data,
websiteType,
showPlayerStats,
loadingPlayerData,
} = this.state;
if (this.state.textColor !== undefined) { if (this.state.textColor !== undefined) {
const element = document.querySelector("." + styles.main); const element = document.querySelector("." + styles.main);
@ -378,7 +393,7 @@ export default class Overlay extends Component {
</div> </div>
) : ( ) : (
<div className={styles.overlay}> <div className={styles.overlay}>
{this.state.showPlayerStats ? ( {showPlayerStats && !loadingPlayerData ? (
<PlayerStats <PlayerStats
pp={data.pp.toLocaleString()} pp={data.pp.toLocaleString()}
globalPos={data.rank.toLocaleString()} globalPos={data.rank.toLocaleString()}