From 1bfee312bf6a176f50bc6751ad6d3cb8a80be5d8 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 10 Mar 2021 17:50:22 +0100 Subject: game status in recent games thingy works better now --- components/recentGames.tsx | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) (limited to 'components') diff --git a/components/recentGames.tsx b/components/recentGames.tsx index 750a9e7..92855a1 100644 --- a/components/recentGames.tsx +++ b/components/recentGames.tsx @@ -1,7 +1,7 @@ import { CSSProperties } from 'react'; import friendlyTime from 'friendly-time'; -import { gameInfo, outcome } from '../api/api'; +import { gameInfo } from '../api/api'; var LeftAlignedTableColumn: CSSProperties = { textAlign: "left", @@ -13,21 +13,29 @@ var RightAlignedTableColumn: CSSProperties = { paddingRight: 16 } -function GameOutcome(props: { outcome: outcome }) { +function GameOutcome(props: { game: gameInfo }) { + var gameStatus = (() => { + return { + "resign": () => "Opgegeven", + "wait_for_opponent": () => "Aan het wachten op een tegenstander", + "in_progress": () => "Bezig", + "finished": () => { + return { + "w": "Gewonnen", + "l": "Verloren", + "d": "Gelijkspel" + }[props.game.outcome] + }, + }[props.game.status](); + })(); + var outcome = props.game.outcome; return { - { - "w": "Gewonnen", - "l": "Verloren", - "d": "Gelijkspel" - }[props.outcome] - } + color: + outcome == "w" ? "var(--disk-b-text)" : + outcome == "l" ? "var(--disk-a-text)" : + "var(--text)", + opacity: !["w", "l"].includes(outcome) ? 0.75 : 1.0 + }}>{gameStatus} } export default function RecentGames(props: { games?: Array }) { @@ -43,9 +51,9 @@ export default function RecentGames(props: { games?: Array }) { { props.games?.map(game => - {game.opponent.username} - - {game.moves.length -1} + {game.opponent?.username} + + {Math.max(0, game.moves.length -1)} {(() => { var timeCreated = new Date(game.created); return friendlyTime(timeCreated); -- cgit v1.2.3