diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-03-06 16:37:11 +0100 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-03-06 16:37:11 +0100 |
commit | bd5dd17eb91f6501fb1944040e9d547c148a60aa (patch) | |
tree | 246f05a958ca4ab99e68e7f1a01f3b955ecdd8ce /web/pw-server/src/routes/index.svelte | |
parent | 47ec2c6721c53ab047c43d75b16fbec9f8db5750 (diff) | |
download | planetwars.dev-bd5dd17eb91f6501fb1944040e9d547c148a60aa.tar.xz planetwars.dev-bd5dd17eb91f6501fb1944040e9d547c148a60aa.zip |
refactor: move bot api calls to submitpane
Diffstat (limited to 'web/pw-server/src/routes/index.svelte')
-rw-r--r-- | web/pw-server/src/routes/index.svelte | 38 |
1 files changed, 3 insertions, 35 deletions
diff --git a/web/pw-server/src/routes/index.svelte b/web/pw-server/src/routes/index.svelte index dec3294..a78c1ea 100644 --- a/web/pw-server/src/routes/index.svelte +++ b/web/pw-server/src/routes/index.svelte @@ -38,45 +38,13 @@ (editSession as any).on("change", debounce(saveCode, 2000)); } - async function submitBot(e: CustomEvent) { - console.log(e.detail); - let response = await fetch("/api/submit_bot", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - code: editSession.getDocument().getValue(), - opponent_name: e.detail["opponentName"], - }), - }); - - if (!response.ok) { - throw Error(response.statusText); - } - - let responseData = await response.json(); - - let matchData = responseData["match"]; - + async function onMatchCreated(e: CustomEvent) { + const matchData = e.detail["match"]; matches.unshift(matchData); matches = matches; await selectMatch(matchData["id"]); } - async function saveBot(e: CustomEvent) { - let response = await fetch("/api/save_bot", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - bot_name: e.detail["botName"], - code: editSession.getDocument().getValue(), - }), - }); - } - async function selectMatch(matchId: string) { selectedMatchId = matchId; selectedMatchLog = null; @@ -183,7 +151,7 @@ {#if selectedMatchId} <OutputPane matchLog={selectedMatchLog} /> {:else} - <SubmitPane on:submitBot={submitBot} on:saveBot={saveBot} /> + <SubmitPane {editSession} on:matchCreated={onMatchCreated} /> {/if} </div> </div> |