From 47ec2c6721c53ab047c43d75b16fbec9f8db5750 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Sat, 5 Mar 2022 12:10:41 +0100 Subject: fix opponent selection --- web/pw-server/src/lib/components/SubmitPane.svelte | 11 +++++------ web/pw-server/src/routes/index.svelte | 4 +++- 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'web') diff --git a/web/pw-server/src/lib/components/SubmitPane.svelte b/web/pw-server/src/lib/components/SubmitPane.svelte index d647b46..588a5e7 100644 --- a/web/pw-server/src/lib/components/SubmitPane.svelte +++ b/web/pw-server/src/lib/components/SubmitPane.svelte @@ -3,12 +3,9 @@ import Select from "svelte-select"; let availableBots: object[] = []; - let selectedOpponent = "simplebot"; + let selectedOpponent = undefined; let botName: string | undefined = undefined; - const optionIdentifier = "name"; - const labelIdentifier = "name"; - onMount(async () => { const res = await fetch("/api/bots", { headers: { @@ -18,14 +15,16 @@ if (res.ok) { availableBots = await res.json(); - console.log(availableBots); + selectedOpponent = availableBots.find((b) => b["name"] === "simplebot"); } }); const dispatch = createEventDispatcher(); function submitBot() { - dispatch("submitBot"); + dispatch("submitBot", { + opponentName: selectedOpponent["name"], + }); } function saveBot() { diff --git a/web/pw-server/src/routes/index.svelte b/web/pw-server/src/routes/index.svelte index b9e5c2e..dec3294 100644 --- a/web/pw-server/src/routes/index.svelte +++ b/web/pw-server/src/routes/index.svelte @@ -38,7 +38,8 @@ (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", { method: "POST", headers: { @@ -46,6 +47,7 @@ }, body: JSON.stringify({ code: editSession.getDocument().getValue(), + opponent_name: e.detail["opponentName"], }), }); -- cgit v1.2.3