aboutsummaryrefslogtreecommitdiff
path: root/web/pw-server/src/lib/components/Leaderboard.svelte
blob: ea303843e9aa60955b838c119a4c6da0979482c3 (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
<script lang="ts">
  export let leaderboard;

  function formatRating(entry: object): any {
    const rating = entry["rating"];
    if (rating != null) {
      return rating.toFixed(0);
    } else {
      // why does this happen?
      return "-inf";
    }
  }
</script>

<div class="container">
  <table class="leaderboard">
    <tr class="leaderboard-row leaderboard-header">
      <th class="leaderboard-rank" />
      <th class="leaderboard-rating">Rating</th>
      <th class="leaderboard-bot">Bot</th>
      <th class="leaderboard-author">Author</th>
    </tr>
    {#each leaderboard as entry, index}
      <tr class="leaderboard-row">
        <td class="leaderboard-rank">{index + 1}</td>
        <td class="leaderboard-rating">
          {formatRating(entry)}
        </td>
        <td class="leaderboard-bot">
          <a class="leaderboard-href" href="/bots/{entry['bot']['name']}"
            >{entry["bot"]["name"]}
          </a></td
        >
        <td class="leaderboard-author">
          {#if entry["author"]}
            <!-- TODO: remove duplication -->
            <a class="leaderboard-href" href="/users/{entry['author']['username']}"
              >{entry["author"]["username"]}</a
            >
          {/if}
        </td>
      </tr>
    {/each}
  </table>
</div>

<style lang="scss">
  .container {
    overflow-y: scroll;
    height: 100%;
  }
  .leaderboard {
    margin: 18px auto;
    text-align: center;
  }

  .leaderboard th,
  .leaderboard td {
    padding: 8px 16px;
  }
  .leaderboard-rank {
    color: #333;
  }

  .leaderboard-href {
    text-decoration: none;
    color: black;
  }
</style>