From e08b6266357d7079b2fdf32e23d23aa5ace17a20 Mon Sep 17 00:00:00 2001 From: Carla Paiva Date: Sat, 3 Feb 2024 17:31:01 -0300 Subject: [PATCH 1/2] feat: add cascader instead of select --- .../upload-step/upload-step.tsx | 48 ++++++++++++++----- src/components/video-converter/index.tsx | 5 ++ src/model/format.ts | 4 ++ 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/components/converter/converter-steps/upload-step/upload-step.tsx b/src/components/converter/converter-steps/upload-step/upload-step.tsx index 6e557e8..c4c9b49 100644 --- a/src/components/converter/converter-steps/upload-step/upload-step.tsx +++ b/src/components/converter/converter-steps/upload-step/upload-step.tsx @@ -1,4 +1,5 @@ -import { Alert, Button, Select, UploadFile } from 'antd' +/* eslint-disable @typescript-eslint/no-explicit-any */ +import { Alert, Button, Cascader, UploadFile } from 'antd' import DraggerUpload from '../../../dragger-upload' import './upload-step.css' import { memo, useCallback, useMemo, useState } from 'react' @@ -17,6 +18,12 @@ type ErrorMessage = { message: string } +type Option = { + value: string + label: string + children?: Option[] +} + const hideErrorMessage: ErrorMessage = { isVisible: false, message: '', @@ -65,9 +72,9 @@ const UploadStep = memo(function UploadStepComponent( }, [props.allowedUploadingFormats]) const onSelectedFormatChange = useCallback( - (value: string) => { - setFormat(value) - props.updateSelectedExtension(value) + (value: (string | number)[]) => { + setFormat(value[1] as string) + props.updateSelectedExtension(value[1] as string) }, [props], ) @@ -87,22 +94,39 @@ const UploadStep = memo(function UploadStepComponent( }, [files.length, format, props]) const options = useMemo(() => { - return props.extensionOptions.map((item) => { - return { value: item.extension, label: item.name } + const opts: Option[] = [] + + props.extensionOptions.forEach((item) => { + if (opts.some((x) => x.label === item.category)) { + return + } + + const children = props.extensionOptions.filter( + (value) => value.category === item.category, + ) + + opts.push({ + label: item.category, + value: item.category, + children: children.map((cItem) => { + return { value: cItem.extension, label: cItem.name, children: [] } + }), + }) }) + + return opts }, [props.extensionOptions]) return (
- + onChange={onSelectedFormatChange} + />