diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-02-02 19:36:18 +0100 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-02-02 19:36:18 +0100 |
commit | db45cea37e8070e1572cdc25121c46022780f51d (patch) | |
tree | 8d522c51f760c691f06267d599f29868591288f1 /web/pw-server/src/routes | |
parent | 2e3606f1b6ba59975b3a0141ed3b2f6286c66ec3 (diff) | |
download | planetwars.dev-db45cea37e8070e1572cdc25121c46022780f51d.tar.xz planetwars.dev-db45cea37e8070e1572cdc25121c46022780f51d.zip |
temporary setup for showing submission match result
Diffstat (limited to 'web/pw-server/src/routes')
-rw-r--r-- | web/pw-server/src/routes/index.svelte | 11 | ||||
-rw-r--r-- | web/pw-server/src/routes/submission_matches/[match_id].svelte | 31 |
2 files changed, 38 insertions, 4 deletions
diff --git a/web/pw-server/src/routes/index.svelte b/web/pw-server/src/routes/index.svelte index 0e811b3..a2a2e61 100644 --- a/web/pw-server/src/routes/index.svelte +++ b/web/pw-server/src/routes/index.svelte @@ -1,4 +1,6 @@ <script lang="ts"> + import { goto } from "$app/navigation"; + let code = ""; async function submitCode() { @@ -9,7 +11,7 @@ "Content-Type": "application/json", }, body: JSON.stringify({ - "code": code, + code: code, }), }); @@ -17,11 +19,12 @@ throw Error(response.statusText); } - let responseData = await response.json() - console.log(responseData); + let responseData = await response.json(); + let matchId = responseData["match_id"]; + goto(`/submission_matches/${matchId}`); } </script> <h1>Planetwars</h1> <textarea bind:value={code} /> -<button on:click={submitCode}>Submit</button>
\ No newline at end of file +<button on:click={submitCode}>Submit</button> diff --git a/web/pw-server/src/routes/submission_matches/[match_id].svelte b/web/pw-server/src/routes/submission_matches/[match_id].svelte new file mode 100644 index 0000000..586b2c2 --- /dev/null +++ b/web/pw-server/src/routes/submission_matches/[match_id].svelte @@ -0,0 +1,31 @@ +<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> |