Skip to content

Commit

Permalink
ExtensionMap type and handler for extension check
Browse files Browse the repository at this point in the history
  • Loading branch information
interim17 committed Oct 5, 2023
1 parent b9017a7 commit 70962e5
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/containers/ConversionForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ interface ConversionProps {
setError: ActionCreator<SetErrorAction>;
}

interface ExtensionMap {
[key: string]: string;
}

const validFileExtensions: ExtensionMap = { Smoldyn: "txt" };

const selectOptions = Object.keys(AvailableEngines).map(
(engineName: string, index) => {
const values = Object.values(AvailableEngines);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -108,9 +122,8 @@ const ConversionForm = ({
bordered={true}
defaultValue="Select"
options={selectOptions}
onChange={() => {
setConversionEngine();
setEngineSelected(true);
onChange={(selectedValue) => {
handleEngineChange(selectedValue);
}}
/>
<Upload
Expand Down

0 comments on commit 70962e5

Please sign in to comment.