From fb8c2aa1c390aeb1922471ee975f192275674610 Mon Sep 17 00:00:00 2001 From: Ralex91 <95540504+Ralex91@users.noreply.github.com> Date: Thu, 1 Feb 2024 11:30:33 +0100 Subject: [PATCH] Update Result rank text --- socket/src/utils/round.js | 12 +++++++----- src/components/game/states/Answers.jsx | 6 +++--- src/components/game/states/Question.jsx | 2 +- src/components/game/states/Result.jsx | 5 ++++- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/socket/src/utils/round.js b/socket/src/utils/round.js index 7e9eae1..728c671 100644 --- a/socket/src/utils/round.js +++ b/socket/src/utils/round.js @@ -73,10 +73,9 @@ export const startRound = async (game, io, socket) => { game.players.find((p) => p.id === player.id).points += points setTimeout(() => { - let rank = - game.players - .sort((a, b) => b.points - a.points) - .findIndex((p) => p.id === player.id) + 1 + let sortPlayers = game.players.sort((a, b) => b.points - a.points) + + let rank = sortPlayers.findIndex((p) => p.id === player.id) + 1 io.to(player.id).emit("game:status", { name: "SHOW_RESULT", @@ -86,7 +85,10 @@ export const startRound = async (game, io, socket) => { points: points, myPoints: player.points, totalPlayer: game.players.length, - rank: rank, + rank, + aheadOfMe: sortPlayers[rank - 2] + ? sortPlayers[rank - 2].username + : null, }, }) }, 200) diff --git a/src/components/game/states/Answers.jsx b/src/components/game/states/Answers.jsx index 6d17e6f..50cff8f 100644 --- a/src/components/game/states/Answers.jsx +++ b/src/components/game/states/Answers.jsx @@ -99,12 +99,12 @@ export default function Answers({
+ {`You are top ${rank}` + (aheadOfMe ? ", behind " + aheadOfMe : "")} +
{correct && ( +{points}