fix opponent selection

This commit is contained in:
Ilion Beyst 2022-03-05 12:10:41 +01:00
parent af04709fe1
commit 47ec2c6721
2 changed files with 8 additions and 7 deletions

View file

@ -3,12 +3,9 @@
import Select from "svelte-select"; import Select from "svelte-select";
let availableBots: object[] = []; let availableBots: object[] = [];
let selectedOpponent = "simplebot"; let selectedOpponent = undefined;
let botName: string | undefined = undefined; let botName: string | undefined = undefined;
const optionIdentifier = "name";
const labelIdentifier = "name";
onMount(async () => { onMount(async () => {
const res = await fetch("/api/bots", { const res = await fetch("/api/bots", {
headers: { headers: {
@ -18,14 +15,16 @@
if (res.ok) { if (res.ok) {
availableBots = await res.json(); availableBots = await res.json();
console.log(availableBots); selectedOpponent = availableBots.find((b) => b["name"] === "simplebot");
} }
}); });
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
function submitBot() { function submitBot() {
dispatch("submitBot"); dispatch("submitBot", {
opponentName: selectedOpponent["name"],
});
} }
function saveBot() { function saveBot() {

View file

@ -38,7 +38,8 @@
(editSession as any).on("change", debounce(saveCode, 2000)); (editSession as any).on("change", debounce(saveCode, 2000));
} }
async function submitBot() { async function submitBot(e: CustomEvent) {
console.log(e.detail);
let response = await fetch("/api/submit_bot", { let response = await fetch("/api/submit_bot", {
method: "POST", method: "POST",
headers: { headers: {
@ -46,6 +47,7 @@
}, },
body: JSON.stringify({ body: JSON.stringify({
code: editSession.getDocument().getValue(), code: editSession.getDocument().getValue(),
opponent_name: e.detail["opponentName"],
}), }),
}); });