aboutsummaryrefslogtreecommitdiff
path: root/web/pw-server/src/lib/components/SubmitPane.svelte
blob: cfdb6728bd4bd38c78d599f0016f0d4be06f2f4b (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<script lang="ts">
  import { createEventDispatcher, onMount } from "svelte";
  import Select from "svelte-select";

  let availableBots: object[] = [];
  let selectedOpponent = "simplebot";

  const optionIdentifier = "name";
  const labelIdentifier = "name";

  onMount(async () => {
    const res = await fetch("/api/bots", {
      headers: {
        "Content-Type": "application/json",
      },
    });

    if (res.ok) {
      availableBots = await res.json();
      console.log(availableBots);
    }
  });

  const dispatch = createEventDispatcher();

  function submit() {
    dispatch("submit");
  }
</script>

<div class="submit-pane">
  <div class="match-form">
    <div class="play-text">Select an opponent to test your bot</div>
    <div class="opponentSelect">
      <Select
        optionIdentifier="name"
        labelIdentifier="name"
        items={availableBots}
        bind:value={selectedOpponent}
      />
    </div>
    <button class="play-button" on:click={submit}>Play</button>
  </div>
</div>

<style lang="scss">
  .submit-pane {
    margin: 20px;
    flex: 1;
  }

  .opponentSelect {
    margin: 20px 0;
  }

  .play-button {
    padding: 8px 16px;
    border-radius: 8px;
    border: 0;
    font-size: 18pt;
    display: block;
    margin: 10px auto;
    background-color: lightgreen;
    cursor: pointer;
  }
</style>