From ff27f8debe251cd89d961c151f403fb40707a937 Mon Sep 17 00:00:00 2001 From: Chesterkxng Date: Wed, 10 Dec 2025 16:50:18 +0100 Subject: [PATCH] chore: select values populated through AUDIO_FORMATS iteration --- .../converters/audio-converter/index.tsx | 57 ++++++++----------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/src/pages/tools/converters/audio-converter/index.tsx b/src/pages/tools/converters/audio-converter/index.tsx index 10f55a5..1654bf7 100644 --- a/src/pages/tools/converters/audio-converter/index.tsx +++ b/src/pages/tools/converters/audio-converter/index.tsx @@ -8,10 +8,7 @@ import SelectWithDesc from '@components/options/SelectWithDesc'; import { convertAudio } from './service'; import { useTranslation } from 'react-i18next'; import { GetGroupsType } from '@components/options/ToolOptions'; - -type InitialValuesType = { - outputFormat: 'mp3' | 'aac' | 'wav'; -}; +import { InitialValuesType, AUDIO_FORMATS, AudioFormat } from './types'; const initialValues: InitialValuesType = { outputFormat: 'mp3' @@ -26,6 +23,24 @@ export default function AudioConverter({ const [result, setResult] = useState(null); const [loading, setLoading] = useState(false); + const compute = async ( + values: InitialValuesType, + inputFile: File | null + ): Promise => { + if (!inputFile) return; + + try { + setLoading(true); + const resultFile = await convertAudio(inputFile, values); + setResult(resultFile); + } catch (error) { + console.error('Conversion failed:', error); + setResult(null); + } finally { + setLoading(false); + } + }; + // Explicitly type getGroups to match GetGroupsType const getGroups: GetGroupsType = ({ values, @@ -42,17 +57,11 @@ export default function AudioConverter({ - updateField( - 'outputFormat', - value as InitialValuesType['outputFormat'] - ) - } - options={[ - { label: 'MP3', value: 'mp3' }, - { label: 'AAC', value: 'aac' }, - { label: 'WAV', value: 'wav' } - ]} + onChange={(value) => updateField('outputFormat', value)} + options={Object.entries(AUDIO_FORMATS).map(([value]) => ({ + label: value.toUpperCase(), + value: value as AudioFormat + }))} description={t( 'audioConverter.outputFormatDescription', 'Select the desired output audio format' @@ -63,24 +72,6 @@ export default function AudioConverter({ } ]; - const compute = async ( - values: InitialValuesType, - inputFile: File | null - ): Promise => { - if (!inputFile) return; - - try { - setLoading(true); - const resultFile = await convertAudio(inputFile, values.outputFormat); - setResult(resultFile); - } catch (error) { - console.error('Conversion failed:', error); - setResult(null); - } finally { - setLoading(false); - } - }; - return (