aboutsummaryrefslogtreecommitdiff
path: root/web/pw-server/src/lib
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-04-25 19:47:31 +0200
committerIlion Beyst <ilion.beyst@gmail.com>2022-04-25 19:47:31 +0200
commit41f1679ef46238aff86e1811f73007b88eb4d53b (patch)
treee25fe7409648943789aed41786d90a0e2537a1fd /web/pw-server/src/lib
parentc43839f4713828de4820ca82d2a99b0eb5f7651f (diff)
downloadplanetwars.dev-41f1679ef46238aff86e1811f73007b88eb4d53b.tar.xz
planetwars.dev-41f1679ef46238aff86e1811f73007b88eb4d53b.zip
persist saved bot name
Diffstat (limited to 'web/pw-server/src/lib')
-rw-r--r--web/pw-server/src/lib/bot_code.ts9
-rw-r--r--web/pw-server/src/lib/components/SubmitPane.svelte4
2 files changed, 13 insertions, 0 deletions
diff --git a/web/pw-server/src/lib/bot_code.ts b/web/pw-server/src/lib/bot_code.ts
index 688587e..29eac68 100644
--- a/web/pw-server/src/lib/bot_code.ts
+++ b/web/pw-server/src/lib/bot_code.ts
@@ -1,6 +1,7 @@
import defaultBotCode from "../assets/bot_template.txt?raw";
const BOT_CODE_KEY = "bot_code";
+const BOT_NAME_KEY = "bot_name";
export function getBotCode(): string {
let botCode = localStorage.getItem(BOT_CODE_KEY);
@@ -17,3 +18,11 @@ export function hasBotCode(): boolean {
export function saveBotCode(botCode: string) {
localStorage.setItem(BOT_CODE_KEY, botCode);
}
+
+export function getBotName(): string | null {
+ return localStorage.getItem(BOT_NAME_KEY);
+}
+
+export function saveBotName(name: string) {
+ localStorage.setItem(BOT_NAME_KEY, name);
+}
diff --git a/web/pw-server/src/lib/components/SubmitPane.svelte b/web/pw-server/src/lib/components/SubmitPane.svelte
index 4d5172e..20a6a39 100644
--- a/web/pw-server/src/lib/components/SubmitPane.svelte
+++ b/web/pw-server/src/lib/components/SubmitPane.svelte
@@ -1,5 +1,6 @@
<script lang="ts">
import { get_session_token } from "$lib/auth";
+ import { getBotName, saveBotName } from "$lib/bot_code";
import { currentUser } from "$lib/stores/current_user";
import { createEventDispatcher, onMount } from "svelte";
@@ -14,6 +15,8 @@
let saveErrors: string[] = [];
onMount(async () => {
+ botName = getBotName();
+
const res = await fetch("/api/bots", {
headers: {
"Content-Type": "application/json",
@@ -68,6 +71,7 @@
let responseData = await response.json();
if (response.ok) {
dispatch("botSaved", responseData);
+ saveBotName(botName);
// clear errors
saveErrors = [];
} else {