diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-08-21 21:18:06 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-08-21 21:18:06 +0200 |
commit | 8eec57f5606c1d1757383f4c0ca40d2cc3334572 (patch) | |
tree | 49d69c8864f59db52061f1222a43e00266e6ab04 | |
parent | 64d24c9e3d7e744788644b00cdb2ec44a999d9cd (diff) | |
download | planetwars.dev-8eec57f5606c1d1757383f4c0ca40d2cc3334572.tar.xz planetwars.dev-8eec57f5606c1d1757383f4c0ca40d2cc3334572.zip |
extract leaderboard from editor
-rw-r--r-- | web/pw-server/src/lib/components/Leaderboard.svelte | 17 | ||||
-rw-r--r-- | web/pw-server/src/routes/__layout.svelte | 3 | ||||
-rw-r--r-- | web/pw-server/src/routes/editor.svelte | 10 | ||||
-rw-r--r-- | web/pw-server/src/routes/leaderboard.svelte | 28 |
4 files changed, 32 insertions, 26 deletions
diff --git a/web/pw-server/src/lib/components/Leaderboard.svelte b/web/pw-server/src/lib/components/Leaderboard.svelte index d29d5d6..ea30384 100644 --- a/web/pw-server/src/lib/components/Leaderboard.svelte +++ b/web/pw-server/src/lib/components/Leaderboard.svelte @@ -1,20 +1,5 @@ <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); - } - }); + export let leaderboard; function formatRating(entry: object): any { const rating = entry["rating"]; diff --git a/web/pw-server/src/routes/__layout.svelte b/web/pw-server/src/routes/__layout.svelte index 2267491..1ef4b8e 100644 --- a/web/pw-server/src/routes/__layout.svelte +++ b/web/pw-server/src/routes/__layout.svelte @@ -13,6 +13,9 @@ <div class="navbar-item"> <a href="/editor">Editor</a> </div> + <div class="navbar-item"> + <a href="/leaderboard">Leaderboard</a> + </div> </div> <div class="navbar-right"> <UserControls /> diff --git a/web/pw-server/src/routes/editor.svelte b/web/pw-server/src/routes/editor.svelte index 85c2454..e85f572 100644 --- a/web/pw-server/src/routes/editor.svelte +++ b/web/pw-server/src/routes/editor.svelte @@ -19,7 +19,6 @@ Editor, MatchVisualizer, Rules, - Leaderboard, } let matches = []; @@ -153,13 +152,6 @@ > Rules </div> - <div - class="sidebar-item" - class:selected={viewMode === ViewMode.Leaderboard} - on:click={() => setViewMode(ViewMode.Leaderboard)} - > - Leaderboard - </div> <div class="sidebar-header">match history</div> <ul class="match-list"> {#each matches as match} @@ -184,8 +176,6 @@ <EditorView {editSession} /> {:else if viewMode === ViewMode.Rules} <RulesView /> - {:else if viewMode === ViewMode.Leaderboard} - <Leaderboard /> {/if} </div> <div class="sidebar-right"> diff --git a/web/pw-server/src/routes/leaderboard.svelte b/web/pw-server/src/routes/leaderboard.svelte new file mode 100644 index 0000000..7c4da6e --- /dev/null +++ b/web/pw-server/src/routes/leaderboard.svelte @@ -0,0 +1,28 @@ +<script lang="ts" context="module"> + import { ApiClient } from "$lib/api_client"; + + export async function load({ fetch }) { + try { + const apiClient = new ApiClient(fetch); + const leaderboard = await apiClient.get("/api/leaderboard"); + return { + props: { + leaderboard, + }, + }; + } catch (error) { + return { + status: error.status, + error: error, + }; + } + } +</script> + +<script lang="ts"> + import Leaderboard from "$lib/components/Leaderboard.svelte"; + + export let leaderboard: object[]; +</script> + +<Leaderboard {leaderboard} /> |