aboutsummaryrefslogtreecommitdiff
path: root/web/pw-server/src/routes
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-03-04 20:23:58 +0100
committerIlion Beyst <ilion.beyst@gmail.com>2022-03-04 20:23:58 +0100
commitaf04709fe16ea9463179a0c3c11d227e83b548d1 (patch)
treebf9b8280f39e5e8093de365d37a87ed74be1803a /web/pw-server/src/routes
parenta8986d7a2892038937548630e36f583eccc3b6f5 (diff)
downloadplanetwars.dev-af04709fe16ea9463179a0c3c11d227e83b548d1.tar.xz
planetwars.dev-af04709fe16ea9463179a0c3c11d227e83b548d1.zip
add save bot form
Diffstat (limited to 'web/pw-server/src/routes')
-rw-r--r--web/pw-server/src/routes/index.svelte17
1 files changed, 15 insertions, 2 deletions
diff --git a/web/pw-server/src/routes/index.svelte b/web/pw-server/src/routes/index.svelte
index a7b1884..b9e5c2e 100644
--- a/web/pw-server/src/routes/index.svelte
+++ b/web/pw-server/src/routes/index.svelte
@@ -38,7 +38,7 @@
(editSession as any).on("change", debounce(saveCode, 2000));
}
- async function submitCode() {
+ async function submitBot() {
let response = await fetch("/api/submit_bot", {
method: "POST",
headers: {
@@ -62,6 +62,19 @@
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;
@@ -168,7 +181,7 @@
{#if selectedMatchId}
<OutputPane matchLog={selectedMatchLog} />
{:else}
- <SubmitPane on:submit={submitCode} />
+ <SubmitPane on:submitBot={submitBot} on:saveBot={saveBot} />
{/if}
</div>
</div>