aboutsummaryrefslogtreecommitdiff
path: root/web/pw-server/src/routes/index.svelte
blob: 0db994c8185f51277ac3d6f5f82ee2023e9a64ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<script lang="ts">
  import { goto } from "$app/navigation";
  import { onMount } from "svelte";

  let editor;

  onMount(async () => {
    const ace = await import("ace-builds");
    editor = ace.edit("editor");
  });

  async function submitCode() {
    if (editor === undefined) {
      return;
    }

    let response = await fetch("/api/submit_bot", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        code: editor.getValue(),
      }),
    });

    if (!response.ok) {
      throw Error(response.statusText);
    }

    let responseData = await response.json();
    let matchId = responseData["match_id"];
    goto(`/submission_matches/${matchId}`);
  }
</script>

<h1>Planetwars</h1>
<div id="editor" />
<button on:click={submitCode}>Submit</button>

<style scoped>
  #editor {
    width: 100%;
    max-width: 800px;
    height: 600px;
  }
</style>