From 4454f2e089701fd2867b236a2237fc2a60afb72e Mon Sep 17 00:00:00 2001 From: Divlo Date: Thu, 23 Apr 2020 01:08:54 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20Bug=20et=20am=C3=A9liorat?= =?UTF-8?q?ions=20globale?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/assets/functions/main/armstrongNumber.js | 2 +- api/assets/functions/main/convertCurrency.js | 2 +- api/assets/functions/main/convertEncoding.js | 2 +- website/components/FunctionForm.js | 13 ++++++++++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/api/assets/functions/main/armstrongNumber.js b/api/assets/functions/main/armstrongNumber.js index 84c4a97..2c5d704 100644 --- a/api/assets/functions/main/armstrongNumber.js +++ b/api/assets/functions/main/armstrongNumber.js @@ -23,7 +23,7 @@ function armstrongNumber(number) { const isArmstrongNumber = (result === number); return { isArmstrongNumber, - resultHTML: `

${formattedNumber} ${isArmstrongNumber ? "" : "n'"}est pas un nombre d'Armstrong, car ${resultString.slice(2)} = ${formatNumberResult(result)}.

` + resultHTML: `

${formattedNumber} ${isArmstrongNumber ? "est" : "n'est pas"} un nombre d'Armstrong, car ${resultString.slice(2)} = ${formatNumberResult(result)}.

` } } diff --git a/api/assets/functions/main/convertCurrency.js b/api/assets/functions/main/convertCurrency.js index 8efb5e2..92bdb29 100644 --- a/api/assets/functions/main/convertCurrency.js +++ b/api/assets/functions/main/convertCurrency.js @@ -30,7 +30,7 @@ module.exports = convertCurrencyOutput = ({ res, next }, argsObject) => { const day = ('0'+(dateObject.getDate())).slice(-2); const month = ('0'+(dateObject.getMonth()+1)).slice(-2); const date = `${day}/${month}/${year}`; - const resultHTML = `

${formatNumberResult(number)} ${response.data.base} = ${formatNumberResult(result).toFixed(2)} ${finalCurrency}

Dernier rafraîchissement du taux d'échange : ${data}

`; + const resultHTML = `

${formatNumberResult(number)} ${response.data.base} = ${formatNumberResult(result.toFixed(2))} ${finalCurrency}

Dernier rafraîchissement du taux d'échange : ${date}

`; return res.status(200).json({ date, result, resultHTML }); }) .catch(() => errorHandling(next, { message: "La devise n'existe pas.", statusCode: 404 })); diff --git a/api/assets/functions/main/convertEncoding.js b/api/assets/functions/main/convertEncoding.js index 1aa395f..8db3b26 100644 --- a/api/assets/functions/main/convertEncoding.js +++ b/api/assets/functions/main/convertEncoding.js @@ -124,7 +124,7 @@ function numberUnicodeToText(string) { const array = string.split(" "); let resultat = ""; for (let index in array) { - resultat = resultat + String.fromCodePoint(parseInt(array[index]).toString()); + resultat += String.fromCodePoint(parseInt(array[index]).toString()); } return resultat; } diff --git a/website/components/FunctionForm.js b/website/components/FunctionForm.js index 2f9b3c2..d1af5d3 100644 --- a/website/components/FunctionForm.js +++ b/website/components/FunctionForm.js @@ -1,4 +1,4 @@ -import { Fragment, useState } from 'react'; +import { Fragment, useState, useEffect } from 'react'; import Loader from './Loader'; import htmlParser from 'html-react-parser'; import dynamic from 'next/dynamic'; @@ -16,6 +16,17 @@ const FunctionForm = (props) => { const [message, setMessage] = useState(""); const [isLoading, setIsLoading] = useState(false); + // inputState par défaut + useEffect(() => { + const inputStateNew = { ...inputState }; + props.inputsArray.forEach((input) => { + if (input.type === "select" && input.options.length > 0) { + inputStateNew[input.name] = input.options[0].value; + } + }); + setInputState(inputStateNew); + }, []); + const handleSubmit = (event) => { setIsLoading(true); event.preventDefault();