// @flow import React from 'react'; import { FormField } from 'component/common/form'; import { VIDEO_QUALITY_OPTIONS } from 'constants/video'; import { toCapitalCase } from 'util/string'; type Props = { defaultQuality: ?string, doSetDefaultVideoQuality: (value: ?string) => void, }; export default function SettingDefaultQuality(props: Props) { const { defaultQuality, doSetDefaultVideoQuality } = props; const [enabled, setEnabled] = React.useState(Boolean(defaultQuality)); const valueRef = React.useRef(VIDEO_QUALITY_OPTIONS[0]); function handleEnable() { if (enabled) { setEnabled(false); // From enabled to disabled -> clear the setting doSetDefaultVideoQuality(null); } else { setEnabled(true); // From to disabled to enabled -> set the current shown value doSetDefaultVideoQuality(valueRef.current); } } function handleSetQuality(e) { const { value } = e.target; doSetDefaultVideoQuality(value); valueRef.current = value; } return ( <> {VIDEO_QUALITY_OPTIONS.map((quality) => { const qualityStr = typeof quality === 'number' ? quality + 'p' : toCapitalCase(quality); return ( ); })} ); }