From 03cdbbc003b102156194568a7b8fc52d636f87f4 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Sun, 16 Oct 2022 12:42:20 +0200 Subject: only show playerlog to bot owner --- web/pw-server/src/routes/matches/[match_id].svelte | 69 ++++++++++++++-------- 1 file changed, 44 insertions(+), 25 deletions(-) (limited to 'web/pw-server/src/routes/matches') diff --git a/web/pw-server/src/routes/matches/[match_id].svelte b/web/pw-server/src/routes/matches/[match_id].svelte index b3d9f01..1d18375 100644 --- a/web/pw-server/src/routes/matches/[match_id].svelte +++ b/web/pw-server/src/routes/matches/[match_id].svelte @@ -35,46 +35,61 @@ matchLog = await apiClient.getText(`/api/matches/${matchData["id"]}/log`); }); - let selectedPlayer; - - $: matchPlayerSelectItems = matchData["players"].map((player: any, index: number) => ({ - color: PLAYER_COLORS[index], - value: index, - playerId: index + 1, // stoopid player number + 1 - label: player["bot_name"], - })); + $: playersWithVisibleLog = matchData["players"] + .map((player: any, index: number) => ({ + color: PLAYER_COLORS[index], + value: index, + playerId: index + 1, // stoopid player number + 1 + displayName: player["bot_name"] || "player", + matchPlayer: player, + })) + .filter((item) => canSeePlayerLog($currentUser, item.matchPlayer)); // TODO: refactor match logs so that users can no longer get match logs for other players. - function currentUserCanSeeStdErr(matchPlayer: object): boolean { + function canSeePlayerLog(user: object | null, matchPlayer: object): boolean { if (!matchPlayer["owner_id"]) { return true; } - console.log(matchPlayer, $currentUser); - return matchPlayer["owner_id"] === $currentUser?.["user_id"]; + return matchPlayer["owner_id"] === user?.["user_id"]; } - $: showStdErr = - !!selectedPlayer && currentUserCanSeeStdErr(matchData["players"][selectedPlayer["value"]]); + // using the same value here causes svelte to freeze + let dropdownSelectedPlayer: any; + let selectedPlayer: any; + $: if (playersWithVisibleLog.length == 1) { + selectedPlayer = playersWithVisibleLog[0]; + } else { + selectedPlayer = dropdownSelectedPlayer; + }
- + {#if playersWithVisibleLog.length == 1} +

+ player log for + {selectedPlayer.displayName} +

+ {:else} + + {/if}
- +
@@ -90,7 +105,11 @@ } .player-select { - padding: 20px; + padding: 0 20px; + } + + .player-log-header { + color: #eee; } .player-log { -- cgit v1.2.3