Skip to content

Commit

Permalink
feat: add cascader instead of select
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlaPaiva committed Feb 3, 2024
1 parent e0f66fc commit e08b626
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -17,6 +18,12 @@ type ErrorMessage = {
message: string
}

type Option = {
value: string
label: string
children?: Option[]
}

const hideErrorMessage: ErrorMessage = {
isVisible: false,
message: '',
Expand Down Expand Up @@ -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],
)
Expand All @@ -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 (
<div className="container">
<DraggerUpload accept={acceptedTypes} onUploadDone={onUploadDone} />
<Select
value={format}
placeholder="Convert all to..."
size="large"
<Cascader
className="container__items"
onChange={onSelectedFormatChange}
size="large"
placeholder="Convert all to..."
options={options}
></Select>
onChange={onSelectedFormatChange}
/>
<Button
size="large"
type="primary"
Expand Down
5 changes: 5 additions & 0 deletions src/components/video-converter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,27 @@ const optionsToConvertTo: Format[] = [
{
name: 'GIF',
extension: '.gif',
category: 'Image',
},
{
name: 'MP4',
extension: '.mp4',
category: 'Video',
},
{
name: 'AVI',
extension: '.avi',
category: 'Video',
},
{
name: 'WMV',
extension: '.wmv',
category: 'Video',
},
{
name: 'MP3',
extension: '.mp3',
category: 'Audio',
},
]

Expand Down
4 changes: 4 additions & 0 deletions src/model/format.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/** Defines a format */
type FormatCategory = 'Image' | 'Audio' | 'Video' | 'File'

export type Format = {
/** Name o the format */
name: string
/** Extension with a dot */
extension: string
/** Category of the format */
category: FormatCategory
}

0 comments on commit e08b626

Please sign in to comment.