aboutsummaryrefslogtreecommitdiff
path: root/web/pw-server/src/routes/index.svelte
blob: a2a2e6114c3d4b9b8be22212b9c6cc185c82a683 (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
<script lang="ts">
  import { goto } from "$app/navigation";

  let code = "";

  async function submitCode() {
    console.log("click");
    let response = await fetch("/api/submit_bot", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        code: code,
      }),
    });

    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>
<textarea bind:value={code} />
<button on:click={submitCode}>Submit</button>