From 91e284d685dab7525c9526be1cb264a7a9c65c5c Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 10 Mar 2021 16:03:54 +0100 Subject: recent games on user page working :tada: --- components/recentGames.tsx | 79 ++++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 34 deletions(-) (limited to 'components/recentGames.tsx') diff --git a/components/recentGames.tsx b/components/recentGames.tsx index a14194f..9e87b61 100644 --- a/components/recentGames.tsx +++ b/components/recentGames.tsx @@ -1,4 +1,7 @@ -import { CSSProperties, Component } from 'react'; +import { CSSProperties } from 'react'; +import friendlyTime from 'friendly-time'; + +import { gameInfo, outcome } from '../api/api'; var LeftAlignedTableColumn: CSSProperties = { textAlign: "left", @@ -10,39 +13,47 @@ var RightAlignedTableColumn: CSSProperties = { paddingRight: 16 } -export default class RecentGames extends Component { - constructor(props: { - user?: string; - }) { - super(props); - } +function GameOutcome(props: { outcome: outcome }) { + return { + { + "w": "Gewonnen", + "l": "Verloren", + "d": "Gelijkspel" + }[props.outcome] + } +} - render () { - return
-

Recente partijen

- - - - - - - - - - - - - - - - - - - - - -
TegenstanderUitkomstZettenDatum
Naam hierGewonnen7Vandaag
Nog meer namenGelijkspel42Gisteren
-
- } +export default function RecentGames(props: { games?: Array }) { + return
+

Recente partijen

+ + + + + + + + + { + props.games?.map(game => + + + + + ) + } + +
TegenstanderUitkomstZettenDatum
{game.opponent}{game.moves.length -1}{(() => { + var timeCreated = new Date(game.created); + return friendlyTime(timeCreated); + })()}
+
} -- cgit v1.2.3