import variables from 'config/variables'; import { useState, useEffect } from 'react'; import { toast } from 'react-toastify'; import { TextField } from '@mui/material'; import { Header, Row, Content, Action, PreferencesWrapper } from 'components/Layout/Settings'; import { Hero, Preview, Controls } from 'components/Layout/Settings/Hero'; import { Dropdown, Checkbox } from 'components/Form/Settings'; import EventBus from 'utils/eventbus'; import searchEngines from '../search_engines.json'; import defaults from './default'; import SearchPreview from './SearchPreview'; function SearchOptions() { const [customEnabled, setCustomEnabled] = useState(false); const [customValue, setCustomValue] = useState( localStorage.getItem('customSearchEngine') || defaults.customSearchEngine, ); function resetSearch() { localStorage.removeItem('customSearchEngine'); setCustomValue(''); toast(variables.getMessage('toasts.reset')); } useEffect(() => { if (localStorage.getItem('searchEngine') === 'custom') { setCustomEnabled(true); } else { localStorage.removeItem('customSearchEngine'); } }, []); useEffect(() => { if (customEnabled === true && customValue !== '') { localStorage.setItem('customSearchEngine', customValue); } EventBus.emit('refresh', 'search'); }, [customEnabled, customValue]); function setSearchEngine(input) { if (input === 'custom') { setCustomEnabled(true); } else { setCustomEnabled(false); localStorage.setItem('searchEngine', input); } EventBus.emit('refresh', 'search'); } const SEARCH_SECTION = 'settings:sections.search'; const AdditionalOptions = () => { return ( {/* not supported on firefox */} {navigator.userAgent.includes('Chrome') && typeof InstallTrigger === 'undefined' ? ( ) : null} ); }; const SearchEngineSelection = () => { return ( setSearchEngine(value)} items={[ ...searchEngines.map((engine) => ({ value: engine.settingsName, text: engine.name, })), { value: 'custom', text: variables.getMessage(`${SEARCH_SECTION}.custom`), }, ]} /> ); }; const CustomOptions = () => { return ( setCustomValue(e.target.value)} varient="outlined" InputLabelProps={{ shrink: true }} />

resetSearch()}> {variables.getMessage('settings:buttons.reset')}

); }; return ( <>
{customEnabled && CustomOptions()} ); } export { SearchOptions as default, SearchOptions };