From 82ca2791c3ebffd6a252ec502abd3ba2a0a81211 Mon Sep 17 00:00:00 2001 From: Nathaniel Tampus Date: Sun, 5 Mar 2023 22:27:36 +0800 Subject: [PATCH] improve player names format --- client/src/components/game/GamePage.tsx | 37 ++++++++++++++++++------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/client/src/components/game/GamePage.tsx b/client/src/components/game/GamePage.tsx index 71dee6e..a5fe3b9 100644 --- a/client/src/components/game/GamePage.tsx +++ b/client/src/components/game/GamePage.tsx @@ -308,6 +308,31 @@ export default function GamePage({ initialLobby }: { initialLobby: Game }) { socket.emit("joinAsPlayer"); } + function getPlayerHtml(side: "top" | "bottom") { + const blackHtml = ( +
+ + {lobby.black?.name || "(no one)"} + + black +
+ ); + const whiteHtml = ( +
+ + {lobby.white?.name || "(no one)"} + + white +
+ ); + + if (lobby.black?.id === session?.user?.id) { + return side === "top" ? whiteHtml : blackHtml; + } else { + return side === "top" ? blackHtml : whiteHtml; + } + } + return (
@@ -352,17 +377,9 @@ export default function GamePage({ initialLobby }: { initialLobby: Game }) {
-
- {session?.user?.id === lobby.black?.id - ? lobby.white?.name || "(no one)" - : lobby.black?.name || "(no one)"} -
+ {getPlayerHtml("top")}
vs
-
- {session?.user?.id === lobby.black?.id - ? lobby.black?.name || "(no one)" - : lobby.white?.name || "(no one)"} -
+ {getPlayerHtml("bottom")}