import React from 'react'; import Dropdown from '../Dropdown'; import Checkbox from '../Checkbox'; import Switch from '../Switch'; import Radio from '../Radio'; import EventBus from '../../../../../modules/helpers/eventbus'; import { toast } from 'react-toastify'; const searchEngines = require('../../../../widgets/search/search_engines.json'); const autocompleteProviders = require('../../../../widgets/search/autocomplete_providers.json') export default class SearchSettings extends React.PureComponent { constructor() { super(); this.state = { customEnabled: false, customDisplay: 'none', customValue: localStorage.getItem('customSearchEngine') || '' }; } resetSearch() { localStorage.removeItem('customSearchEngine'); this.setState({ customValue: '' }); toast(window.language.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() { const language = window.language.modals.main.settings; const { search } = language.sections; return ( <>

{search.title}

{(navigator.userAgent.includes('Chrome') && typeof InstallTrigger === 'undefined') ? : null} this.setSearchEngine(value)}> {searchEngines.map((engine) => ( ))}
); } }