From 39cec55bbe738a4c5f93913b9b016050a1953d10 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Sat, 16 Apr 2022 10:30:11 +0200 Subject: format & cleanup --- web/pw-server/src/hooks.js | 10 +++---- web/pw-server/src/lib/components/RulesView.svelte | 1 - .../src/lib/components/navbar/UserControls.svelte | 3 +- web/pw-server/src/lib/utils.ts | 35 ++++++++++++++++++++++ web/pw-server/src/routes/matches/new.svelte | 4 +-- .../routes/submission_matches/[match_id].svelte | 31 ------------------- 6 files changed, 44 insertions(+), 40 deletions(-) delete mode 100644 web/pw-server/src/routes/submission_matches/[match_id].svelte (limited to 'web') diff --git a/web/pw-server/src/hooks.js b/web/pw-server/src/hooks.js index c5785ed..7916c84 100644 --- a/web/pw-server/src/hooks.js +++ b/web/pw-server/src/hooks.js @@ -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; -} \ No newline at end of file + return response; +} diff --git a/web/pw-server/src/lib/components/RulesView.svelte b/web/pw-server/src/lib/components/RulesView.svelte index c3cf125..58e6bf2 100644 --- a/web/pw-server/src/lib/components/RulesView.svelte +++ b/web/pw-server/src/lib/components/RulesView.svelte @@ -64,7 +64,6 @@ padding: 15px; overflow-y: scroll; height: 100%; - margin-bottom: 200px; box-sizing: border-box; } diff --git a/web/pw-server/src/lib/components/navbar/UserControls.svelte b/web/pw-server/src/lib/components/navbar/UserControls.svelte index 3c1d181..0b8413d 100644 --- a/web/pw-server/src/lib/components/navbar/UserControls.svelte +++ b/web/pw-server/src/lib/components/navbar/UserControls.svelte @@ -1,5 +1,5 @@ diff --git a/web/pw-server/src/lib/utils.ts b/web/pw-server/src/lib/utils.ts index aab9734..155d952 100644 --- a/web/pw-server/src/lib/utils.ts +++ b/web/pw-server/src/lib/utils.ts @@ -1,3 +1,5 @@ +import { get_session_token } from "./auth"; + export function debounce(func: Function, timeout: number = 300) { let timer: ReturnType; 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); +} diff --git a/web/pw-server/src/routes/matches/new.svelte b/web/pw-server/src/routes/matches/new.svelte index eed3dbb..ebc0e15 100644 --- a/web/pw-server/src/routes/matches/new.svelte +++ b/web/pw-server/src/routes/matches/new.svelte @@ -28,7 +28,7 @@ - - - -
- -
-- cgit v1.2.3