From 70962e5d0338b1806384a7cbd2ff0f6df94974ec Mon Sep 17 00:00:00 2001 From: Joe Heffernan Date: Thu, 5 Oct 2023 16:11:12 -0700 Subject: [PATCH] ExtensionMap type and handler for extension check --- src/containers/ConversionForm/index.tsx | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/containers/ConversionForm/index.tsx b/src/containers/ConversionForm/index.tsx index e9a90c07..e19da1b7 100644 --- a/src/containers/ConversionForm/index.tsx +++ b/src/containers/ConversionForm/index.tsx @@ -37,6 +37,12 @@ interface ConversionProps { setError: ActionCreator; } +interface ExtensionMap { + [key: string]: string; +} + +const validFileExtensions: ExtensionMap = { Smoldyn: "txt" }; + const selectOptions = Object.keys(AvailableEngines).map( (engineName: string, index) => { const values = Object.values(AvailableEngines); @@ -65,12 +71,20 @@ const ConversionForm = ({ setIsProcessing(!isProcessing); }; + const handleEngineChange = (selectedValue: string) => { + const selectedEngine = selectedValue as AvailableEngines; + setConversionEngine(selectedEngine); + setEngineSelected(true); + }; + const validateFileType = () => { if (fileToConvert) { const fileExtension = fileToConvert.name.split(".").pop()?.toLowerCase() || ""; - const validExtensions = ["smoldyn"]; - if (validExtensions.includes(fileExtension)) { + if ( + validFileExtensions[conversionProcessingData.engineType] === + fileExtension + ) { setIsProcessing(!isProcessing); return; } @@ -108,9 +122,8 @@ const ConversionForm = ({ bordered={true} defaultValue="Select" options={selectOptions} - onChange={() => { - setConversionEngine(); - setEngineSelected(true); + onChange={(selectedValue) => { + handleEngineChange(selectedValue); }} />