import variables from 'config/variables'; import { PureComponent } from 'react'; import { toast } from 'react-toastify'; import { MenuItem, TextField } from '@mui/material'; import { Header, Row, Content, Action, PreferencesWrapper } from 'components/Layout/Settings'; import { Dropdown, Checkbox } from 'components/Form/Settings'; import EventBus from 'utils/eventbus'; import searchEngines from 'features/widgets/search/search_engines.json'; class SearchOptions extends PureComponent { constructor() { super(); this.state = { customEnabled: false, customValue: localStorage.getItem('customSearchEngine') || '', }; } resetSearch() { localStorage.removeItem('customSearchEngine'); this.setState({ customValue: '', }); toast(variables.getMessage('toasts.reset')); } componentDidMount() { if (localStorage.getItem('searchEngine') === 'custom') { this.setState({ customEnabled: true, }); } else { localStorage.removeItem('customSearchEngine'); } } componentDidUpdate() { if (this.state.customEnabled === true && this.state.customValue !== '') { localStorage.setItem('customSearchEngine', this.state.customValue); } EventBus.emit('refresh', 'search'); } setSearchEngine(input) { if (input === 'custom') { this.setState({ customEnabled: true, }); } else { this.setState({ customEnabled: false, }); localStorage.setItem('searchEngine', input); } EventBus.emit('refresh', 'search'); } render() { const SEARCH_SECTION = 'modals.main.settings.sections.search'; const AdditionalOptions = () => { return ( {/* not supported on firefox */} {navigator.userAgent.includes('Chrome') && typeof InstallTrigger === 'undefined' ? ( ) : null} ); }; const SearchEngineSelection = () => { return ( this.setSearchEngine(value)} items={[ searchEngines.map((engine) => ({ value: engine.settingsName, text: engine.name, })), { value: 'custom', text: variables.getMessage(`${SEARCH_SECTION}.custom`), }, ]} /> ); }; const CustomOptions = () => { return ( this.setState({ customValue: e.target.value })} varient="outlined" InputLabelProps={{ shrink: true }} /> this.resetSearch()}> {variables.getMessage('modals.main.settings.buttons.reset')} ); }; return ( <> {this.state.customEnabled && CustomOptions()} > ); } } export { SearchOptions as default, SearchOptions };
this.resetSearch()}> {variables.getMessage('modals.main.settings.buttons.reset')}