aboutsummaryrefslogtreecommitdiff
path: root/web/pw-server
diff options
context:
space:
mode:
Diffstat (limited to 'web/pw-server')
-rw-r--r--web/pw-server/src/lib/components/Leaderboard.svelte17
-rw-r--r--web/pw-server/src/routes/__layout.svelte3
-rw-r--r--web/pw-server/src/routes/editor.svelte10
-rw-r--r--web/pw-server/src/routes/leaderboard.svelte28
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} />