format & cleanup

This commit is contained in:
Ilion Beyst 2022-04-16 10:30:11 +02:00
parent a41b4c48cb
commit 39cec55bbe
6 changed files with 44 additions and 40 deletions

View file

@ -1,8 +1,8 @@
/** @type {import('@sveltejs/kit').Handle} */
export async function handle({ event, resolve }) {
const response = await resolve(event, {
ssr: false,
});
const response = await resolve(event, {
ssr: false,
});
return response;
}
return response;
}

View file

@ -64,7 +64,6 @@
padding: 15px;
overflow-y: scroll;
height: 100%;
margin-bottom: 200px;
box-sizing: border-box;
}
</style>

View file

@ -1,5 +1,5 @@
<script lang="ts">
import { get_session_token } from "$lib/auth";
import { get_session_token, clear_session_token } from "$lib/auth";
import { currentUser } from "$lib/stores/current_user";
import { onMount } from "svelte";
@ -30,6 +30,7 @@
function signOut() {
// TODO: destroy session on server
currentUser.set(null);
clear_session_token();
}
</script>

View file

@ -1,3 +1,5 @@
import { get_session_token } from "./auth";
export function debounce(func: Function, timeout: number = 300) {
let timer: ReturnType<typeof setTimeout>;
return (...args: any[]) => {
@ -7,3 +9,36 @@ export function debounce(func: Function, timeout: number = 300) {
}, timeout);
};
}
export async function get(url: string, fetch_fn: Function = fetch) {
const headers = { "Content-Type": "application/json" };
const token = get_session_token();
if (token) {
headers["Authorization"] = `Bearer ${token}`;
}
const response = await fetch_fn(url, {
method: "GET",
headers,
});
return JSON.parse(response);
}
export async function post(url: string, data: any, fetch_fn: Function = fetch) {
const headers = { "Content-Type": "application/json" };
const token = get_session_token();
if (token) {
headers["Authorization"] = `Bearer ${token}`;
}
const response = await fetch_fn(url, {
method: "POST",
headers,
body: JSON.stringify(data),
});
return JSON.parse(response);
}

View file

@ -28,7 +28,7 @@
<script lang="ts">
import Select from "svelte-select";
import { goto } from "$app/navigation";
import { goto } from "$app/navigation";
export let bots: object[];
let items: object[];
let players: object[] = [];
@ -65,7 +65,7 @@ import { goto } from "$app/navigation";
if (res.ok) {
// TODO
goto("/matches")
goto("/matches");
} else {
alert(res.statusText);
}

View file

@ -1,31 +0,0 @@
<script lang="ts" context="module">
export async function load({ page }) {
const res = await fetch(`/api/submission_match_log/${page.params["match_id"]}`, {
headers: {
"Content-Type": "application/json",
},
});
if (res.ok) {
return {
props: {
matchLog: await res.text(),
},
};
}
return {
status: res.status,
error: new Error("failed to load match"),
};
}
</script>
<script lang="ts">
import Visualizer from "$lib/components/Visualizer.svelte";
export let matchLog: string;
</script>
<div>
<Visualizer {matchLog} />
</div>