// @flow import React, { useState } from 'react'; import { FormField } from 'component/common/form'; import Spinner from 'component/spinner'; import SUPPORTED_LANGUAGES from 'constants/supported_languages'; import { getDefaultLanguage, sortLanguageMap } from 'util/default-languages'; type Props = { language: string, setLanguage: (string) => void, searchInLanguage: boolean, setSearchInLanguage: (boolean) => void, }; function SettingLanguage(props: Props) { const { language, setLanguage, searchInLanguage, setSearchInLanguage } = props; const [previousLanguage, setPreviousLanguage] = useState(null); if (previousLanguage && language !== previousLanguage) { setPreviousLanguage(null); } function onLanguageChange(e) { const { value } = e.target; setPreviousLanguage(language || getDefaultLanguage()); setLanguage(value); } return ( {sortLanguageMap(SUPPORTED_LANGUAGES).map(([langKey, langName]) => ( ))} {previousLanguage && } setSearchInLanguage(!searchInLanguage)} /> ); } export default SettingLanguage;