ProfilePageView: fix winrate
This commit is contained in:
@ -21,7 +21,7 @@ export default class extends AbstractView {
|
||||
await this.fillHistory(games);
|
||||
await this.fillStatistics(games);
|
||||
|
||||
if (this.profile.id === client.me.id)
|
||||
if (!client.me || this.profile.id === client.me.id)
|
||||
return;
|
||||
|
||||
const addFriendButton = document.getElementById('addFriendButton'),
|
||||
@ -78,7 +78,7 @@ export default class extends AbstractView {
|
||||
*/
|
||||
async fillStatistics(games)
|
||||
{
|
||||
let winrateDiv = document.getElementById("winrate");
|
||||
const winrateDiv = document.getElementById("winrate");
|
||||
|
||||
let win = 0;
|
||||
let lose = 0;
|
||||
@ -87,13 +87,17 @@ export default class extends AbstractView {
|
||||
if (game.finished === false)
|
||||
return
|
||||
|
||||
if (client.me.id === game.winner.id)
|
||||
if (this.profile.id === game.winner.id)
|
||||
win++;
|
||||
else
|
||||
lose++;
|
||||
});
|
||||
|
||||
winrateDiv.innerText = `winrate: ${win + lose === 0 ? "🤓" : win / (win + lose)}`
|
||||
if (games.length) {
|
||||
winrateDiv.innerText = `Winrate: ${win / (win + lose) * 100}%`;
|
||||
} else {
|
||||
winrateDiv.innerText = `Winrate: 🤓`
|
||||
}
|
||||
}
|
||||
|
||||
async fillHistory(games)
|
||||
|
Reference in New Issue
Block a user