aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api/api.ts2
-rw-r--r--api/user/games.py7
-rw-r--r--components/recentGames.tsx44
-rw-r--r--pages/user.tsx2
4 files changed, 31 insertions, 24 deletions
diff --git a/api/api.ts b/api/api.ts
index 1db6e0e..1cf50ef 100644
--- a/api/api.ts
+++ b/api/api.ts
@@ -50,7 +50,7 @@ export interface gameInfo {
duration: number;
id: string;
moves: Array<number>;
- opponent: userInfo;
+ opponent?: userInfo;
outcome: outcome;
parent?: string;
private: boolean;
diff --git a/api/user/games.py b/api/user/games.py
index 009e5ee..1cd19f2 100644
--- a/api/user/games.py
+++ b/api/user/games.py
@@ -30,12 +30,13 @@ def game_info(game_id, user_id = None):
"private", # 13
]) + " from games where game_id = ?", [game_id]).fetchone()
is_player_1 = game[4] != user_id
+ opponent = game[4] if is_player_1 else game[3]
return {
"id": game[0],
"parent": game[1],
- "moves": [int(move) for move in str(game[2]).split(",")],
- "opponent": format_user(game[4] if is_player_1 else game[3]),
- "outcome": outcome(game[5], is_player_1),
+ "moves": [] if len(game[2]) == 0 else [int(move) for move in str(game[2] + "0").split(",")],
+ "opponent": None if not opponent else format_user(opponent),
+ "outcome": None if not game[5] else outcome(game[5], is_player_1),
"created": game[6],
"started": game[7],
"duration": game[8],
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 <td style={{
- color: {
- "w": "var(--disk-b-text)",
- "l": "var(--disk-a-text)",
- "d": "var(--text)"
- }[props.outcome],
- opacity: props.outcome == "d" ? 0.75 : 1.0
- }}>{
- {
- "w": "Gewonnen",
- "l": "Verloren",
- "d": "Gelijkspel"
- }[props.outcome]
- }</td>
+ 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}</td>
}
export default function RecentGames(props: { games?: Array<gameInfo> }) {
@@ -43,9 +51,9 @@ export default function RecentGames(props: { games?: Array<gameInfo> }) {
</tr>
{
props.games?.map(game => <tr>
- <td style={LeftAlignedTableColumn}>{game.opponent.username}</td>
- <GameOutcome outcome={game.outcome}/>
- <td>{game.moves.length -1}</td>
+ <td style={LeftAlignedTableColumn}>{game.opponent?.username}</td>
+ <GameOutcome game={game}/>
+ <td>{Math.max(0, game.moves.length -1)}</td>
<td style={RightAlignedTableColumn}>{(() => {
var timeCreated = new Date(game.created);
return friendlyTime(timeCreated);
diff --git a/pages/user.tsx b/pages/user.tsx
index 280f8e2..6462109 100644
--- a/pages/user.tsx
+++ b/pages/user.tsx
@@ -109,8 +109,6 @@ export default function AccountPage() {
data: { "id": id || self_id }
});
- console.log(userGamesReq.data)
-
setGameInfo(userGamesReq.data);
} else {
window.history.go(-1);