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

45 lines
1 KiB
React
Raw Normal View History

// @flow
import React from 'react';
2022-03-04 05:21:34 +01:00
import { getLanguageName } from 'constants/languages';
import { FormField } from 'component/common/form';
import { getDefaultHomepageKey } from 'util/default-languages';
type Props = {
homepage: string,
setHomepage: (string) => void,
};
function SelectHomepage(props: Props) {
const { homepage, setHomepage } = props;
2022-03-04 05:21:34 +01:00
const homepages = window.homepages || {};
const homepageKeys = Object.keys(homepages);
function handleSetHomepage(e) {
const { value } = e.target;
setHomepage(value);
}
2022-03-04 05:21:34 +01:00
if (homepageKeys.length <= 1) {
return null;
}
2022-03-04 05:21:34 +01:00
return (
<React.Fragment>
<FormField
name="homepage_select"
type="select"
onChange={handleSetHomepage}
value={homepage || getDefaultHomepageKey()}
>
2022-03-04 05:21:34 +01:00
{homepageKeys.map((hp) => (
<option key={'hp' + hp} value={hp}>
2022-03-04 05:21:34 +01:00
{getLanguageName(hp)}
</option>
))}
</FormField>
</React.Fragment>
);
}
export default SelectHomepage;