From 96af78f967d22e1e6c92057b7472619b0f222c72 Mon Sep 17 00:00:00 2001 From: Divlo Date: Wed, 25 Mar 2020 18:46:23 +0100 Subject: [PATCH] frontend: Hotfix loading --- website/components/FunctionForm.js | 9 +++------ website/pages/register.js | 3 +++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/website/components/FunctionForm.js b/website/components/FunctionForm.js index 08a6cf4..f3f08c1 100644 --- a/website/components/FunctionForm.js +++ b/website/components/FunctionForm.js @@ -11,25 +11,22 @@ const FunctionForm = (props) => { const [isLoading, setIsLoading] = useState(false); const handleSubmit = (event) => { + setIsLoading(true); event.preventDefault(); api.post(`/functions/${props.slug}`, inputState) .then((response) => { setMessage(response.data.resultHTML); + setIsLoading(false); }) .catch((error) => { setMessage(error.response.data.message); + setIsLoading(false); }); - setIsLoading(false); } const handleChange = (event) => { const inputStateNew = { ...inputState }; inputStateNew[event.target.name] = event.target.value; - if (event.target.value !== "") { - setIsLoading(true); - } else { - setIsLoading(false); - } setInputState(inputStateNew); } diff --git a/website/pages/register.js b/website/pages/register.js index 64ccccd..f7fe9f9 100644 --- a/website/pages/register.js +++ b/website/pages/register.js @@ -18,13 +18,16 @@ const Register = () => { } const handleSubmit = (event) => { + setIsLoading(true); event.preventDefault(); api.post('/users/register', inputState) .then(({ data }) => { setMessage(`

Succès: ${data.result}

`); + setIsLoading(false); }) .catch((error) => { setMessage(`

Erreur: ${error.response.data.message}

`); + setIsLoading(false); }); }