lbry-desktop/ui/component/settingDefaultQuality/view.jsx

46 lines
1.2 KiB
React
Raw Normal View History

// @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';
import { toCapitalCase } from 'util/string';
2022-04-22 13:11:24 +02:00
const OPTION_DISABLED = 'Disabled';
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];
function handleSetQuality(e) {
const { value } = e.target;
2022-04-22 13:11:24 +02:00
doSetDefaultVideoQuality(value === OPTION_DISABLED ? null : value);
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) => {
const qualityStr = typeof option === 'number' ? option + 'p' : toCapitalCase(option);
return (
<option key={'quality' + qualityStr} value={option}>
{__(qualityStr)}
</option>
);
})}
</FormField>
);
}