From f9b266dd1f47f6173ee60ed2ec03d844d9753fd7 Mon Sep 17 00:00:00 2001 From: lukaw3d Date: Mon, 28 Oct 2024 17:32:22 +0100 Subject: [PATCH] frontend: pass requestBody to showResponseStatus --- faucet-frontend/src/main.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/faucet-frontend/src/main.js b/faucet-frontend/src/main.js index 0f75e10..63ac4f5 100644 --- a/faucet-frontend/src/main.js +++ b/faucet-frontend/src/main.js @@ -1,9 +1,15 @@ // @ts-check -function showResponseStatus(status) { +function showResponseStatus(error, status, requestBody) { document.querySelector('#request-form').style.display = 'none'; document.querySelector('#response-display').style.display = 'block'; - document.querySelector('#response-display-text').textContent = status; + if (error) { + document.querySelector('#response-display-text').textContent = error; + } else { + document.querySelector('#response-display-text').textContent = status; + if (requestBody.get('paratime') === 'emerald') {} + if (requestBody.get('paratime') === 'sapphire') {} + } } function showLoading(bool) { document.querySelector('#request-form-submit').disabled = bool; @@ -31,10 +37,11 @@ document.querySelector('#request-form').addEventListener('submit', (event) => { /** @type {HTMLFormElement} */ (event.currentTarget); const url = form.action; + const requestBody = new URLSearchParams(new FormData(form)) fetch(url, { method: 'POST', - body: new URLSearchParams(new FormData(form)), + body: requestBody, headers: { Accept: 'application/json', }, @@ -42,10 +49,10 @@ document.querySelector('#request-form').addEventListener('submit', (event) => { .then(response => response.json()) .then((responseJson) => { showLoading(false); - showResponseStatus(responseJson.result); + showResponseStatus(null, responseJson.result, requestBody); }, (error) => { showLoading(false); - showResponseStatus(error); + showResponseStatus(error, null, requestBody); }); // Only prevent native form POST if no errors were thrown until `fetch`