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")}