import variables from 'modules/variables'; import { PureComponent } from 'react'; import { toast } from 'react-toastify'; import Header from '../Header'; import Dropdown from '../Dropdown'; import Checkbox from '../Checkbox'; import Switch from '../Switch'; import Radio from '../Radio'; import EventBus from 'modules/helpers/eventbus'; const searchEngines = require('components/widgets/search/search_engines.json'); const autocompleteProviders = require('components/widgets/search/autocomplete_providers.json'); export default class SearchSettings extends PureComponent { getMessage = (text) => variables.language.getMessage(variables.languagecode, text); constructor() { super(); this.state = { customEnabled: false, customDisplay: 'none', customValue: localStorage.getItem('customSearchEngine') || '' }; } resetSearch() { localStorage.removeItem('customSearchEngine'); this.setState({ customValue: '' }); toast(this.getMessage('toasts.reset')); } componentDidMount() { if (localStorage.getItem('searchEngine') === 'custom') { this.setState({ customDisplay: 'block', customEnabled: true }); } else { localStorage.removeItem('customSearchEngine'); } } componentDidUpdate() { if (this.state.customEnabled === true && this.state.customValue !== '') { localStorage.setItem('customSearchEngine', this.state.customValue); } EventBus.dispatch('refresh', 'search'); } setSearchEngine(input) { if (input === 'custom') { this.setState({ customDisplay: 'block', customEnabled: true }); } else { this.setState({ customDisplay: 'none', customEnabled: false }); localStorage.setItem('searchEngine', input); } EventBus.dispatch('refresh', 'search'); } render() { return ( <>

{this.getMessage('modals.main.settings.sections.search.title')}

{/* not supported on firefox */} {(navigator.userAgent.includes('Chrome') && typeof InstallTrigger === 'undefined') ? : null} this.setSearchEngine(value)}> {searchEngines.map((engine) => ( ))}

    {this.getMessage('modals.main.settings.sections.search.custom')} this.resetSearch()}>{this.getMessage('modals.main.settings.buttons.reset')}

    this.setState({ customValue: e.target.value })}>

); } }