aboutsummaryrefslogtreecommitdiff
path: root/web/pw-server/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'web/pw-server/src/lib')
-rw-r--r--web/pw-server/src/lib/components/SubmitPane.svelte11
-rw-r--r--web/pw-server/src/lib/stores/editor_state.ts26
2 files changed, 33 insertions, 4 deletions
diff --git a/web/pw-server/src/lib/components/SubmitPane.svelte b/web/pw-server/src/lib/components/SubmitPane.svelte
index 82f752e..9fd2380 100644
--- a/web/pw-server/src/lib/components/SubmitPane.svelte
+++ b/web/pw-server/src/lib/components/SubmitPane.svelte
@@ -3,13 +3,14 @@
import { getBotName, saveBotName } from "$lib/bot_code";
import { currentUser } from "$lib/stores/current_user";
+ import { selectedOpponent } from "$lib/stores/editor_state";
+
import { createEventDispatcher, onMount } from "svelte";
import Select from "svelte-select";
export let editSession;
let availableBots: object[] = [];
- let selectedOpponent = undefined;
let botName: string | undefined = undefined;
// whether to show the "save succesful" message
let saveSuccesful = false;
@@ -27,14 +28,16 @@
if (res.ok) {
availableBots = await res.json();
- selectedOpponent = availableBots.find((b) => b["name"] === "simplebot");
+ if (!$selectedOpponent) {
+ selectedOpponent.set(availableBots.find((b) => b["name"] === "simplebot"));
+ }
}
});
const dispatch = createEventDispatcher();
async function submitBot() {
- const opponentName = selectedOpponent["name"];
+ const opponentName = $selectedOpponent["name"];
let response = await fetch("/api/submit_bot", {
method: "POST",
@@ -106,7 +109,7 @@
optionIdentifier="name"
labelIdentifier="name"
items={availableBots}
- bind:value={selectedOpponent}
+ bind:value={$selectedOpponent}
isClearable={false}
/>
</div>
diff --git a/web/pw-server/src/lib/stores/editor_state.ts b/web/pw-server/src/lib/stores/editor_state.ts
new file mode 100644
index 0000000..641994b
--- /dev/null
+++ b/web/pw-server/src/lib/stores/editor_state.ts
@@ -0,0 +1,26 @@
+import { writable } from "svelte/store";
+
+const MAX_MATCHES = 100;
+
+function createMatchHistory() {
+ const { subscribe, update } = writable([]);
+
+ function pushMatch(match: object) {
+ update((matches) => {
+ if (matches.length == MAX_MATCHES) {
+ matches.pop();
+ }
+ matches.unshift(match);
+
+ return matches;
+ });
+ }
+
+ return {
+ subscribe,
+ pushMatch,
+ };
+}
+
+export const matchHistory = createMatchHistory();
+export const selectedOpponent = writable(null);