import variables from 'modules/variables'; import { PureComponent } from 'react'; import { toast } from 'react-toastify'; import { MenuItem, TextField } from '@mui/material'; import Header from '../Header'; import Dropdown from '../Dropdown'; import Checkbox from '../Checkbox'; import SettingsItem from '../SettingsItem'; import EventBus from 'modules/helpers/eventbus'; import searchEngines from 'components/widgets/search/search_engines.json'; export default class SearchSettings extends PureComponent { constructor() { super(); this.state = { customEnabled: false, customDisplay: 'none', customValue: localStorage.getItem('customSearchEngine') || '', }; } resetSearch() { localStorage.removeItem('customSearchEngine'); this.setState({ customValue: '', }); toast(variables.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 ( <>
{/* not supported on firefox */} {navigator.userAgent.includes('Chrome') && typeof InstallTrigger === 'undefined' ? ( ) : null} this.setSearchEngine(value)} manual={true} > {searchEngines.map((engine) => ( {engine.name} ))} {variables.getMessage('modals.main.settings.sections.search.custom').split(' ')[0]}
this.setState({ customValue: e.target.value })} varient="outlined" InputLabelProps={{ shrink: true }} />

this.resetSearch()}> {variables.getMessage('modals.main.settings.buttons.reset')}

); } }