2022-04-19 18:55:32 +02:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
|
|
|
import { FormField } from 'component/common/form';
|
2022-04-20 20:40:21 +02:00
|
|
|
import { VIDEO_QUALITY_OPTIONS } from 'constants/player';
|
2022-04-19 18:55:32 +02:00
|
|
|
import { toCapitalCase } from 'util/string';
|
|
|
|
|
2022-04-22 13:11:24 +02:00
|
|
|
const OPTION_DISABLED = 'Disabled';
|
|
|
|
|
2022-04-19 18:55:32 +02:00
|
|
|
type Props = {
|
|
|
|
defaultQuality: ?string,
|
|
|
|
doSetDefaultVideoQuality: (value: ?string) => void,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function SettingDefaultQuality(props: Props) {
|
|
|
|
const { defaultQuality, doSetDefaultVideoQuality } = props;
|
|
|
|
|
2022-04-22 13:11:24 +02:00
|
|
|
const valueRef = React.useRef();
|
|
|
|
const dropdownOptions = [OPTION_DISABLED, ...VIDEO_QUALITY_OPTIONS];
|
2022-04-19 18:55:32 +02:00
|
|
|
|
|
|
|
function handleSetQuality(e) {
|
|
|
|
const { value } = e.target;
|
2022-04-22 13:11:24 +02:00
|
|
|
|
|
|
|
doSetDefaultVideoQuality(value === OPTION_DISABLED ? null : value);
|
2022-04-19 18:55:32 +02:00
|
|
|
valueRef.current = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-04-22 13:11:24 +02:00
|
|
|
<FormField
|
|
|
|
name="default_video_quality"
|
|
|
|
type="select"
|
|
|
|
onChange={handleSetQuality}
|
|
|
|
value={defaultQuality || valueRef.current}
|
|
|
|
>
|
|
|
|
{dropdownOptions.map((option) => {
|
|
|
|
return (
|
2022-04-29 14:46:54 +02:00
|
|
|
<option key={String(option)} value={option}>
|
|
|
|
{typeof option === 'number' ? `${option}p` : __(toCapitalCase(option))}
|
2022-04-22 13:11:24 +02:00
|
|
|
</option>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</FormField>
|
2022-04-19 18:55:32 +02:00
|
|
|
);
|
|
|
|
}
|