planetwars.dev/web/pw-server/src/routes/index.svelte

48 lines
936 B
Svelte
Raw Normal View History

2022-01-30 23:34:21 +01:00
<script lang="ts">
import { goto } from "$app/navigation";
2022-02-02 23:15:55 +01:00
import { onMount } from "svelte";
2022-02-02 23:15:55 +01:00
let editor;
onMount(async () => {
const ace = await import("ace-builds");
editor = ace.edit("editor");
});
2022-01-30 23:34:21 +01:00
async function submitCode() {
2022-02-02 23:15:55 +01:00
if (editor === undefined) {
return;
}
2022-01-30 23:34:21 +01:00
let response = await fetch("/api/submit_bot", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
2022-02-02 23:15:55 +01:00
code: editor.getValue(),
2022-01-30 23:34:21 +01:00
}),
});
if (!response.ok) {
throw Error(response.statusText);
}
let responseData = await response.json();
let matchId = responseData["match_id"];
goto(`/submission_matches/${matchId}`);
2022-01-30 23:34:21 +01:00
}
</script>
<h1>Planetwars</h1>
2022-02-02 23:15:55 +01:00
<div id="editor" />
<button on:click={submitCode}>Submit</button>
2022-02-02 23:15:55 +01:00
<style scoped>
#editor {
width: 100%;
max-width: 800px;
height: 600px;
}
</style>