diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-03-06 16:58:01 +0100 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-03-06 16:58:01 +0100 |
commit | a8c913f284ef2bc8f4d882682c398ba834159175 (patch) | |
tree | 67c1ec1b14c80964701a75646077b6d74df4e977 /web/pw-server/src/lib | |
parent | 148178a344dd42ccf00356cad06f4e635e78bda7 (diff) | |
download | planetwars.dev-a8c913f284ef2bc8f4d882682c398ba834159175.tar.xz planetwars.dev-a8c913f284ef2bc8f4d882682c398ba834159175.zip |
show errors for saving bots
Diffstat (limited to 'web/pw-server/src/lib')
-rw-r--r-- | web/pw-server/src/lib/components/SubmitPane.svelte | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/web/pw-server/src/lib/components/SubmitPane.svelte b/web/pw-server/src/lib/components/SubmitPane.svelte index 3c9fe22..6a05e09 100644 --- a/web/pw-server/src/lib/components/SubmitPane.svelte +++ b/web/pw-server/src/lib/components/SubmitPane.svelte @@ -8,6 +8,8 @@ let selectedOpponent = undefined; let botName: string | undefined = undefined; + let saveErrorText = undefined; + onMount(async () => { const res = await fetch("/api/bots", { headers: { @@ -62,8 +64,15 @@ let responseData = await response.json(); if (response.ok) { dispatch("botSaved", responseData); + // clear errors + saveErrorText = undefined; } else { - throw responseData; + if (responseData["error"] === "BotNameTaken") { + saveErrorText = "Bot name is already taken"; + } else { + // unexpected error + throw responseData; + } } } </script> @@ -84,6 +93,9 @@ <div class="save-form"> <h4>Save your bot</h4> <input type="text" class="bot-name-input" placeholder="bot name" bind:value={botName} /> + {#if saveErrorText} + <div class="error-text">{saveErrorText}</div> + {/if} <button class="submit-button save-button" on:click={saveBot}>Save</button> </div> </div> @@ -104,6 +116,10 @@ margin-top: 8em; } + .error-text { + color: red; + } + .submit-button { padding: 8px 16px; border-radius: 8px; |