From c24d6a0785b1d6ee96dfeaa2cc1dc8e7ec1a8bf3 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 13 May 2021 21:33:56 -0400 Subject: [PATCH] Add error message to player-settings and weighted-settings pages if the call to /api/generate returns a non-2xx response code. --- WebHostLib/static/assets/playerSettings.js | 6 ++++++ WebHostLib/static/assets/weightedSettings.js | 6 ++++++ WebHostLib/static/styles/playerSettings.css | 14 ++++++++++++++ WebHostLib/static/styles/weightedSettings.css | 6 +++++- WebHostLib/templates/playerSettings.html | 1 + WebHostLib/templates/weightedSettings.html | 1 + 6 files changed, 33 insertions(+), 1 deletion(-) diff --git a/WebHostLib/static/assets/playerSettings.js b/WebHostLib/static/assets/playerSettings.js index e74bd47b..19a871f3 100644 --- a/WebHostLib/static/assets/playerSettings.js +++ b/WebHostLib/static/assets/playerSettings.js @@ -170,6 +170,12 @@ const generateGame = (raceMode = false) => { race: raceMode ? '1' : '0', }).then((response) => { window.location.href = response.data.url; + }).catch((error) => { + const userMessage = document.getElementById('user-message'); + userMessage.innerText = 'Something went wrong and your game could not be generated.'; + userMessage.classList.add('visible'); + window.scrollTo(0, 0); + console.error(error); }); }; diff --git a/WebHostLib/static/assets/weightedSettings.js b/WebHostLib/static/assets/weightedSettings.js index 0eb7765c..ede5dc34 100644 --- a/WebHostLib/static/assets/weightedSettings.js +++ b/WebHostLib/static/assets/weightedSettings.js @@ -473,5 +473,11 @@ const generateGame = (raceMode = false) => { race: raceMode ? '1' : '0', }).then((response) => { window.location.href = response.data.url; + }).catch((error) => { + const userMessage = document.getElementById('user-message'); + userMessage.innerText = 'Something went wrong and your game could not be generated.'; + userMessage.classList.add('visible'); + window.scrollTo(0, 0); + console.error(error); }); }; diff --git a/WebHostLib/static/styles/playerSettings.css b/WebHostLib/static/styles/playerSettings.css index 33a76d3d..ac675ebb 100644 --- a/WebHostLib/static/styles/playerSettings.css +++ b/WebHostLib/static/styles/playerSettings.css @@ -29,6 +29,20 @@ html{ color: #000000; } +#player-settings #user-message{ + display: none; + width: calc(100% - 8px); + background-color: #ffe86b; + border-radius: 4px; + color: #000000; + padding: 4px; + text-align: center; +} + +#player-settings #user-message.visible{ + display: block; +} + #player-settings h1{ font-size: 2.5rem; font-weight: normal; diff --git a/WebHostLib/static/styles/weightedSettings.css b/WebHostLib/static/styles/weightedSettings.css index 14abad09..d887f599 100644 --- a/WebHostLib/static/styles/weightedSettings.css +++ b/WebHostLib/static/styles/weightedSettings.css @@ -14,7 +14,7 @@ html{ color: #eeffeb; } -#user-warning{ +#user-warning, #weighted-settings #user-message{ display: none; width: calc(100% - 8px); background-color: #ffe86b; @@ -25,6 +25,10 @@ html{ cursor: pointer; } +#weighted-settings #user-message.visible{ + display: block; +} + #weighted-settings code{ background-color: #d9cd8e; border-radius: 4px; diff --git a/WebHostLib/templates/playerSettings.html b/WebHostLib/templates/playerSettings.html index 9e156076..cbf743be 100644 --- a/WebHostLib/templates/playerSettings.html +++ b/WebHostLib/templates/playerSettings.html @@ -11,6 +11,7 @@ {% block body %} {% include 'header/grassHeader.html' %}
+

Start Game

Choose the options you would like to play with! You may generate a single-player game from this page, or download a settings file you can use to participate in a MultiWorld. If you would like to make diff --git a/WebHostLib/templates/weightedSettings.html b/WebHostLib/templates/weightedSettings.html index 83af0680..c92cdb88 100644 --- a/WebHostLib/templates/weightedSettings.html +++ b/WebHostLib/templates/weightedSettings.html @@ -12,6 +12,7 @@ {% include 'header/grassHeader.html' %}

+

Weighted Settings

This page is used to configure your weighted settings. You have three presets you can control, which