-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(v2): conversion settings form (#105)
* feat(v2): conversion settings form * add french translations
- Loading branch information
Showing
24 changed files
with
461 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { useTranslation } from 'react-i18next'; | ||
import { codecSchema } from 'src/schemas/conversionSettings.schema'; | ||
import { FormControl, FormItem, FormLabel } from '../ui/Form'; | ||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/Select'; | ||
import type { Bitrate, Codec } from 'src/schemas/conversionSettings.schema'; | ||
|
||
type BitrateSelectProps = { | ||
codec: Codec; | ||
onChange: (value: Bitrate) => void; | ||
value: Bitrate; | ||
}; | ||
|
||
const bitrateByCodec: Record<Codec, Bitrate[]> = { | ||
default: ['default'], | ||
aac: ['default', '32k', '64k', '96k', '128k', '192k', '256k', '320k'], | ||
ac3: ['default', '128k', '192k', '256k', '320k', '384k', '448k', '512k', '640k'], | ||
eac3: ['default', '192k', '320k', '448k', '640k', '1024k', '2048k', '4096k'], | ||
}; | ||
|
||
export const BitrateSelect = ({ codec, value, onChange }: BitrateSelectProps) => { | ||
const { t } = useTranslation(); | ||
const options = bitrateByCodec[codec]; | ||
const isDisabled = codec === codecSchema.enum.default; | ||
|
||
return ( | ||
<FormItem> | ||
<FormLabel>{t('conversionSettings.bitrate.label')}</FormLabel> | ||
<Select disabled={isDisabled} onValueChange={onChange} value={value}> | ||
<FormControl> | ||
<SelectTrigger> | ||
<SelectValue /> | ||
</SelectTrigger> | ||
</FormControl> | ||
<SelectContent> | ||
{options.map(option => ( | ||
<SelectItem key={option} value={option}> | ||
{t(`conversionSettings.bitrate.values.${option}`)} | ||
</SelectItem> | ||
))} | ||
</SelectContent> | ||
</Select> | ||
</FormItem> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { useTranslation } from 'react-i18next'; | ||
import { codecSchema } from 'src/schemas/conversionSettings.schema'; | ||
import { FormControl, FormItem, FormLabel } from '../ui/Form'; | ||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/Select'; | ||
import type { Channels, Codec } from 'src/schemas/conversionSettings.schema'; | ||
|
||
type ChannelsSelectProps = { | ||
codec: Codec; | ||
onChange: (value: Channels) => void; | ||
value: Channels; | ||
}; | ||
|
||
const channelsByCodec: Record<Codec, Channels[]> = { | ||
default: ['default'], | ||
aac: ['default', '1', '2', '3', '4', '5', '6', '7', '8'], | ||
ac3: ['default', '1', '2', '3', '4', '5', '6'], | ||
eac3: ['default', '1', '2', '3', '4', '5', '6'], | ||
}; | ||
|
||
export const ChannelsSelect = ({ codec, onChange, value }: ChannelsSelectProps) => { | ||
const { t } = useTranslation(); | ||
const options = channelsByCodec[codec]; | ||
const isDisabled = codec === codecSchema.enum.default; | ||
|
||
return ( | ||
<FormItem> | ||
<FormLabel>{t('conversionSettings.channels.label')}</FormLabel> | ||
<Select disabled={isDisabled} onValueChange={onChange} value={value}> | ||
<FormControl> | ||
<SelectTrigger> | ||
<SelectValue /> | ||
</SelectTrigger> | ||
</FormControl> | ||
<SelectContent> | ||
{options.map(option => ( | ||
<SelectItem key={option} value={option}> | ||
{t(`conversionSettings.channels.values.${option}`)} | ||
</SelectItem> | ||
))} | ||
</SelectContent> | ||
</Select> | ||
</FormItem> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { useTranslation } from 'react-i18next'; | ||
import { codecSchema } from 'src/schemas/conversionSettings.schema'; | ||
import { FormControl, FormItem, FormLabel } from '../ui/Form'; | ||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/Select'; | ||
import type { Codec } from 'src/schemas/conversionSettings.schema'; | ||
|
||
type CodecSelectProps = { | ||
onChange: (value: Codec) => void; | ||
value: Codec; | ||
}; | ||
|
||
export const CodecSelect = ({ onChange, value }: CodecSelectProps) => { | ||
const { t } = useTranslation(); | ||
const options = codecSchema.options.map(option => option); | ||
|
||
return ( | ||
<FormItem> | ||
<FormLabel>{t('conversionSettings.codec.label')}</FormLabel> | ||
<Select onValueChange={onChange} value={value}> | ||
<FormControl> | ||
<SelectTrigger> | ||
<SelectValue /> | ||
</SelectTrigger> | ||
</FormControl> | ||
<SelectContent> | ||
{options.map(option => ( | ||
<SelectItem key={option} value={option}> | ||
{t(`conversionSettings.codec.values.${option}`)} | ||
</SelectItem> | ||
))} | ||
</SelectContent> | ||
</Select> | ||
</FormItem> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { useEffect } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useConversionSettingsForm } from 'src/hooks/useConversionSettingsForm'; | ||
import { bitrateSchema, channelsSchema, codecSchema, sampleRateSchema } from 'src/schemas/conversionSettings.schema'; | ||
import { Form, FormField } from '../ui/Form'; | ||
import { BitrateSelect } from './BitrateSelect'; | ||
import { ChannelsSelect } from './ChannelsSelect'; | ||
import { CodecSelect } from './CodecSelect'; | ||
import { SampleRateSelect } from './SampleRateSelect'; | ||
|
||
export const ConversionSettings = () => { | ||
const { t } = useTranslation(); | ||
const form = useConversionSettingsForm({ | ||
defaultValues: { | ||
codec: codecSchema.enum.default, | ||
bitrate: bitrateSchema.enum.default, | ||
sampleRate: sampleRateSchema.enum.default, | ||
channels: channelsSchema.enum.default, | ||
}, | ||
}); | ||
const { control, setValue, watch } = form; | ||
const codec = watch('codec'); | ||
|
||
useEffect(() => { | ||
setValue('bitrate', bitrateSchema.enum.default); | ||
setValue('sampleRate', sampleRateSchema.enum.default); | ||
setValue('channels', channelsSchema.enum.default); | ||
}, [codec, setValue]); | ||
|
||
return ( | ||
<Form {...form}> | ||
<form className="flex flex-col gap-4"> | ||
<h2 className="title-sm mb-2">{t('conversionSettings.title')}</h2> | ||
<FormField | ||
control={control} | ||
name="codec" | ||
render={({ field }) => <CodecSelect onChange={field.onChange} value={field.value} />} | ||
/> | ||
<FormField | ||
control={control} | ||
name="bitrate" | ||
render={({ field }) => <BitrateSelect codec={codec} onChange={field.onChange} value={field.value} />} | ||
/> | ||
<FormField | ||
control={control} | ||
name="sampleRate" | ||
render={({ field }) => <SampleRateSelect codec={codec} onChange={field.onChange} value={field.value} />} | ||
/> | ||
<FormField | ||
control={control} | ||
name="channels" | ||
render={({ field }) => <ChannelsSelect codec={codec} onChange={field.onChange} value={field.value} />} | ||
/> | ||
</form> | ||
</Form> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { useTranslation } from 'react-i18next'; | ||
import { codecSchema } from 'src/schemas/conversionSettings.schema'; | ||
import { FormControl, FormItem, FormLabel } from '../ui/Form'; | ||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/Select'; | ||
import type { Codec, SampleRate } from 'src/schemas/conversionSettings.schema'; | ||
|
||
type SampleRateSelectProps = { | ||
codec: Codec; | ||
onChange: (value: SampleRate) => void; | ||
value: SampleRate; | ||
}; | ||
|
||
const sampleRateByCodec: Record<Codec, SampleRate[]> = { | ||
default: ['default'], | ||
aac: ['default', '8000', '22050', '32000', '44100', '48000', '96000'], | ||
ac3: ['default', '8000', '22050', '32000', '44100', '48000'], | ||
eac3: ['default', '32000', '44100', '48000'], | ||
}; | ||
|
||
export const SampleRateSelect = ({ codec, onChange, value }: SampleRateSelectProps) => { | ||
const { t } = useTranslation(); | ||
const options = sampleRateByCodec[codec]; | ||
const isDisabled = codec === codecSchema.enum.default; | ||
|
||
return ( | ||
<FormItem> | ||
<FormLabel>{t('conversionSettings.sampleRate.label')}</FormLabel> | ||
<Select disabled={isDisabled} onValueChange={onChange} value={value}> | ||
<FormControl> | ||
<SelectTrigger> | ||
<SelectValue /> | ||
</SelectTrigger> | ||
</FormControl> | ||
<SelectContent> | ||
{options.map(option => ( | ||
<SelectItem key={option} value={option}> | ||
{t(`conversionSettings.sampleRate.values.${option}`)} | ||
</SelectItem> | ||
))} | ||
</SelectContent> | ||
</Select> | ||
</FormItem> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { ConversionSettings } from './ConversionSettings'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as SeparatorPrimitive from '@radix-ui/react-separator'; | ||
import * as React from 'react'; | ||
import { cn } from 'src/lib/utils'; | ||
import type { PropsWithClassName } from './ui.types'; | ||
|
||
const Separator = React.forwardRef< | ||
React.ElementRef<typeof SeparatorPrimitive.Root>, | ||
React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root> & PropsWithClassName | ||
>(({ className, orientation = 'horizontal', decorative = true, ...props }, ref) => ( | ||
<SeparatorPrimitive.Root | ||
className={cn('shrink-0 bg-border', orientation === 'horizontal' ? 'h-[1px] w-full' : 'h-full w-[1px]', className)} | ||
decorative={decorative} | ||
orientation={orientation} | ||
ref={ref} | ||
{...props} | ||
/> | ||
)); | ||
Separator.displayName = SeparatorPrimitive.Root.displayName; | ||
|
||
export { Separator }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.