mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-12-29 16:16:02 +00:00
chore: select values populated through AUDIO_FORMATS iteration
This commit is contained in:
@@ -8,10 +8,7 @@ import SelectWithDesc from '@components/options/SelectWithDesc';
|
|||||||
import { convertAudio } from './service';
|
import { convertAudio } from './service';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { GetGroupsType } from '@components/options/ToolOptions';
|
import { GetGroupsType } from '@components/options/ToolOptions';
|
||||||
|
import { InitialValuesType, AUDIO_FORMATS, AudioFormat } from './types';
|
||||||
type InitialValuesType = {
|
|
||||||
outputFormat: 'mp3' | 'aac' | 'wav';
|
|
||||||
};
|
|
||||||
|
|
||||||
const initialValues: InitialValuesType = {
|
const initialValues: InitialValuesType = {
|
||||||
outputFormat: 'mp3'
|
outputFormat: 'mp3'
|
||||||
@@ -26,6 +23,24 @@ export default function AudioConverter({
|
|||||||
const [result, setResult] = useState<File | null>(null);
|
const [result, setResult] = useState<File | null>(null);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
const compute = async (
|
||||||
|
values: InitialValuesType,
|
||||||
|
inputFile: File | null
|
||||||
|
): Promise<void> => {
|
||||||
|
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<InitialValuesType>
|
// Explicitly type getGroups to match GetGroupsType<InitialValuesType>
|
||||||
const getGroups: GetGroupsType<InitialValuesType> = ({
|
const getGroups: GetGroupsType<InitialValuesType> = ({
|
||||||
values,
|
values,
|
||||||
@@ -42,17 +57,11 @@ export default function AudioConverter({
|
|||||||
<Box>
|
<Box>
|
||||||
<SelectWithDesc
|
<SelectWithDesc
|
||||||
selected={values.outputFormat}
|
selected={values.outputFormat}
|
||||||
onChange={(value) =>
|
onChange={(value) => updateField('outputFormat', value)}
|
||||||
updateField(
|
options={Object.entries(AUDIO_FORMATS).map(([value]) => ({
|
||||||
'outputFormat',
|
label: value.toUpperCase(),
|
||||||
value as InitialValuesType['outputFormat']
|
value: value as AudioFormat
|
||||||
)
|
}))}
|
||||||
}
|
|
||||||
options={[
|
|
||||||
{ label: 'MP3', value: 'mp3' },
|
|
||||||
{ label: 'AAC', value: 'aac' },
|
|
||||||
{ label: 'WAV', value: 'wav' }
|
|
||||||
]}
|
|
||||||
description={t(
|
description={t(
|
||||||
'audioConverter.outputFormatDescription',
|
'audioConverter.outputFormatDescription',
|
||||||
'Select the desired output audio format'
|
'Select the desired output audio format'
|
||||||
@@ -63,24 +72,6 @@ export default function AudioConverter({
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
const compute = async (
|
|
||||||
values: InitialValuesType,
|
|
||||||
inputFile: File | null
|
|
||||||
): Promise<void> => {
|
|
||||||
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 (
|
return (
|
||||||
<ToolContent
|
<ToolContent
|
||||||
title={title}
|
title={title}
|
||||||
|
|||||||
Reference in New Issue
Block a user