diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-05-28 11:22:44 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-05-28 11:22:44 +0200 |
commit | 80c60ac69c9b0d86a4536eeac82cf266eb4430bc (patch) | |
tree | bc2ac0c803be27395c0297123f0794e1b8904676 /web/pw-server/src/lib/components/Leaderboard.svelte | |
parent | 643c0e7706ab927ef270e4a5b62ada0c38b651b9 (diff) | |
parent | fadcda850332f8adb0a4382da9f04f78db3f6d1a (diff) | |
download | planetwars.dev-80c60ac69c9b0d86a4536eeac82cf266eb4430bc.tar.xz planetwars.dev-80c60ac69c9b0d86a4536eeac82cf266eb4430bc.zip |
Merge branch 'feature/leaderboard'
Diffstat (limited to 'web/pw-server/src/lib/components/Leaderboard.svelte')
-rw-r--r-- | web/pw-server/src/lib/components/Leaderboard.svelte | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/web/pw-server/src/lib/components/Leaderboard.svelte b/web/pw-server/src/lib/components/Leaderboard.svelte new file mode 100644 index 0000000..75e4807 --- /dev/null +++ b/web/pw-server/src/lib/components/Leaderboard.svelte @@ -0,0 +1,72 @@ +<script lang="ts"> + import { onMount } from "svelte"; + + let leaderboard = []; + + onMount(async () => { + const res = await fetch("/api/leaderboard", { + headers: { + "Content-Type": "application/json", + }, + }); + + if (res.ok) { + leaderboard = await res.json(); + console.log(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">{entry["bot"]["name"]}</td> + <td class="leaderboard-author"> + {#if entry["author"]} + {entry["author"]["username"]} + {/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; + } +</style> |