aboutsummaryrefslogtreecommitdiff
path: root/web/pw-frontend/src/lib/MatchBrowser.svelte
blob: aeb45be89bd42ad947979d48c0c20c7167379d52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<script lang="ts">
  import { onMount } from "svelte";
  import Visualizer from "./Visualizer.svelte";
  import moment from "moment";

  const PLAYER_COLORS = [
    "#FF8000",
    "#0080FF",
    "#FF6693",
    "#3FCB55",
    "#CBC33F",
    "#CF40E9",
    "#FF3F0D",
    "#1BEEF0",
    "#0DC5FF",
  ];

  let matches = [];
  let selectedMatch = null;
  let selectedMatchLog = null;

  onMount(() => {
    fetch("/api/matches")
      .then((response) => response.json())
      .then((m) => (matches = m));
  });

  function selectMatch(matchName) {
    selectedMatch = matchName;
    selectedMatchLog = null;
    fetch(`/api/matches/${matchName}`)
      .then((resp) => resp.text())
      .then((log) => {
        selectedMatchLog = log;
      });
  }

  function showTimestamp(dateStr: string): string {
    let t = moment(dateStr);
    if (t.day() == moment().day()) {
      return moment(dateStr).format("HH:mm");
    } else {
      return moment(dateStr).format("DD/MM");
    }
  }

  function playerColor(player_num: number): string {
    return PLAYER_COLORS[player_num % PLAYER_COLORS.length];
  }
</script>

<div class="container">
  <div class="sidebar">
    <div class="sidebar-header" />
    <ul class="match-list">
      {#each matches as match (match.name)}
        <li
          on:click={() => selectMatch(match.name)}
          class:selected={selectedMatch === match.name}
          class="match-card"
        >
          <div class="match-name">{match.name}</div>
          <span class="match-timestamp">{showTimestamp(match.timestamp)}</span>
          <span class="match-mapname">{match.map_name}</span>
          <ul class="match-player-list">
            {#each match.players as player, ix}
              <li class="match-player" style="color: {playerColor(ix)}">
                {player.name}
              </li>
            {/each}
          </ul>
        </li>
      {/each}
    </ul>
  </div>
  <Visualizer matchLog={selectedMatchLog} />
</div>

<style scoped>
  .container {
    display: flex;
    width: 100vw;
    height: 100vh;
    overflow-y: hidden;
    background-color: rgb(41, 41, 41);
  }

  .sidebar {
    width: 20%;
    width: 350px;
    color: #eee;
    overflow: hidden;
    overflow-y: scroll;
    height: 100%;
  }

  .sidebar-header {
    margin-top: 2em;
    text-transform: uppercase;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    font-family: "Open Sans", sans-serif;
    padding-left: 14px;
  }

  .match-list {
    list-style: none;
    padding: 0;
  }

  .match-card {
    padding: 0.5em;
    padding-left: 14px;
  }

  .match-card.selected {
    background-color: #333;
  }

  .match-card:hover {
    background-color: #333;
  }

  .match-timestamp {
    color: #ccc;
  }

  .match-mapname {
    padding: 0 0.5em;
    color: #ccc;
  }

  .match-player-list {
    list-style: none;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-left: 18px;
  }
</style>