2021-09-10 15:38:53 +00:00
|
|
|
import variables from 'modules/variables';
|
2021-08-14 19:10:48 +00:00
|
|
|
import { PureComponent } from 'react';
|
2021-08-15 21:28:37 +00:00
|
|
|
import { toast } from 'react-toastify';
|
2021-10-12 21:18:47 +00:00
|
|
|
import { MenuItem, TextField } from '@mui/material';
|
2021-01-17 18:07:26 +00:00
|
|
|
|
2021-09-26 17:03:32 +00:00
|
|
|
import Header from '../Header';
|
2020-10-27 14:59:45 +00:00
|
|
|
import Dropdown from '../Dropdown';
|
2020-11-29 14:32:08 +00:00
|
|
|
import Checkbox from '../Checkbox';
|
2022-04-08 13:48:36 +00:00
|
|
|
import SettingsItem from '../SettingsItem';
|
2020-09-22 14:43:09 +00:00
|
|
|
|
2021-08-28 14:34:12 +00:00
|
|
|
import EventBus from 'modules/helpers/eventbus';
|
2021-04-12 17:55:02 +00:00
|
|
|
|
2022-04-18 09:43:40 +00:00
|
|
|
import searchEngines from 'components/widgets/search/search_engines.json';
|
2020-09-17 11:42:02 +00:00
|
|
|
|
2021-08-14 19:10:48 +00:00
|
|
|
export default class SearchSettings extends PureComponent {
|
2021-04-10 18:36:58 +00:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.state = {
|
|
|
|
customEnabled: false,
|
|
|
|
customDisplay: 'none',
|
2022-04-11 21:57:07 +00:00
|
|
|
customValue: localStorage.getItem('customSearchEngine') || '',
|
2021-04-10 18:36:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-09-22 14:43:09 +00:00
|
|
|
resetSearch() {
|
|
|
|
localStorage.removeItem('customSearchEngine');
|
2021-04-10 18:36:58 +00:00
|
|
|
this.setState({
|
2022-04-11 21:57:07 +00:00
|
|
|
customValue: '',
|
2021-04-10 18:36:58 +00:00
|
|
|
});
|
2021-03-17 13:01:53 +00:00
|
|
|
|
2022-08-26 09:45:32 +00:00
|
|
|
toast(variables.getMessage('toasts.reset'));
|
2020-09-22 14:43:09 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 11:58:37 +00:00
|
|
|
componentDidMount() {
|
2021-04-10 18:36:58 +00:00
|
|
|
if (localStorage.getItem('searchEngine') === 'custom') {
|
|
|
|
this.setState({
|
|
|
|
customDisplay: 'block',
|
2022-04-11 21:57:07 +00:00
|
|
|
customEnabled: true,
|
2021-04-10 18:36:58 +00:00
|
|
|
});
|
2021-01-16 22:43:46 +00:00
|
|
|
} else {
|
|
|
|
localStorage.removeItem('customSearchEngine');
|
|
|
|
}
|
2020-09-18 11:58:37 +00:00
|
|
|
}
|
|
|
|
|
2021-02-26 12:29:57 +00:00
|
|
|
componentDidUpdate() {
|
2021-04-10 18:36:58 +00:00
|
|
|
if (this.state.customEnabled === true && this.state.customValue !== '') {
|
|
|
|
localStorage.setItem('customSearchEngine', this.state.customValue);
|
2021-02-26 12:29:57 +00:00
|
|
|
}
|
2021-04-12 17:55:02 +00:00
|
|
|
|
|
|
|
EventBus.dispatch('refresh', 'search');
|
2021-02-26 12:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setSearchEngine(input) {
|
|
|
|
if (input === 'custom') {
|
2021-04-10 18:36:58 +00:00
|
|
|
this.setState({
|
|
|
|
customDisplay: 'block',
|
2022-04-11 21:57:07 +00:00
|
|
|
customEnabled: true,
|
2021-04-10 18:36:58 +00:00
|
|
|
});
|
2021-02-26 12:29:57 +00:00
|
|
|
} else {
|
2021-04-10 18:36:58 +00:00
|
|
|
this.setState({
|
|
|
|
customDisplay: 'none',
|
2022-04-11 21:57:07 +00:00
|
|
|
customEnabled: false,
|
2021-04-10 18:36:58 +00:00
|
|
|
});
|
2021-03-17 13:01:53 +00:00
|
|
|
localStorage.setItem('searchEngine', input);
|
2021-02-26 12:29:57 +00:00
|
|
|
}
|
2021-04-12 17:55:02 +00:00
|
|
|
|
|
|
|
EventBus.dispatch('refresh', 'search');
|
2021-02-26 12:29:57 +00:00
|
|
|
}
|
|
|
|
|
2020-09-17 11:42:02 +00:00
|
|
|
render() {
|
|
|
|
return (
|
2021-03-22 22:17:52 +00:00
|
|
|
<>
|
2022-04-11 21:57:07 +00:00
|
|
|
<Header
|
2022-08-26 09:45:32 +00:00
|
|
|
title={variables.getMessage('modals.main.settings.sections.search.title')}
|
2022-04-11 21:57:07 +00:00
|
|
|
setting="searchBar"
|
|
|
|
category="widgets"
|
|
|
|
switch={true}
|
|
|
|
/>
|
2022-05-11 15:09:26 +00:00
|
|
|
<SettingsItem
|
2022-08-26 09:45:32 +00:00
|
|
|
title={variables.getMessage('modals.main.settings.additional_settings')}
|
|
|
|
subtitle={variables.getMessage('modals.main.settings.sections.search.additional')}
|
2022-05-11 15:09:26 +00:00
|
|
|
>
|
2022-04-11 21:57:07 +00:00
|
|
|
{/* not supported on firefox */}
|
|
|
|
{navigator.userAgent.includes('Chrome') && typeof InstallTrigger === 'undefined' ? (
|
|
|
|
<Checkbox
|
|
|
|
name="voiceSearch"
|
2022-08-26 09:45:32 +00:00
|
|
|
text={variables.getMessage('modals.main.settings.sections.search.voice_search')}
|
2022-04-11 21:57:07 +00:00
|
|
|
category="search"
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
<Checkbox
|
|
|
|
name="searchDropdown"
|
2022-08-26 09:45:32 +00:00
|
|
|
text={variables.getMessage('modals.main.settings.sections.search.dropdown')}
|
2022-04-11 21:57:07 +00:00
|
|
|
category="search"
|
|
|
|
element=".other"
|
|
|
|
/>
|
|
|
|
<Checkbox
|
|
|
|
name="searchFocus"
|
2022-08-26 09:45:32 +00:00
|
|
|
text={variables.getMessage('modals.main.settings.sections.search.focus')}
|
2022-04-11 21:57:07 +00:00
|
|
|
category="search"
|
|
|
|
element=".other"
|
|
|
|
/>
|
|
|
|
<Checkbox
|
|
|
|
name="autocomplete"
|
2022-08-26 09:45:32 +00:00
|
|
|
text={variables.getMessage('modals.main.settings.sections.search.autocomplete')}
|
2022-04-11 21:57:07 +00:00
|
|
|
category="search"
|
|
|
|
/>
|
2022-04-08 13:48:36 +00:00
|
|
|
</SettingsItem>
|
2022-04-11 21:57:07 +00:00
|
|
|
<SettingsItem
|
2022-08-26 09:45:32 +00:00
|
|
|
title={variables.getMessage('modals.main.settings.sections.search.search_engine')}
|
|
|
|
subtitle={variables.getMessage(
|
|
|
|
'modals.main.settings.sections.search.search_engine_subtitle',
|
|
|
|
)}
|
2023-01-21 12:10:40 +00:00
|
|
|
final={ this.state.customDisplay === 'none' ? true : false}
|
2022-04-11 21:57:07 +00:00
|
|
|
>
|
|
|
|
<Dropdown
|
|
|
|
name="searchEngine"
|
|
|
|
onChange={(value) => this.setSearchEngine(value)}
|
|
|
|
manual={true}
|
|
|
|
>
|
|
|
|
{searchEngines.map((engine) => (
|
|
|
|
<MenuItem key={engine.name} value={engine.settingsName}>
|
|
|
|
{engine.name}
|
|
|
|
</MenuItem>
|
|
|
|
))}
|
|
|
|
<MenuItem value="custom">
|
2022-08-26 09:45:32 +00:00
|
|
|
{variables.getMessage('modals.main.settings.sections.search.custom').split(' ')[0]}
|
2022-04-11 21:57:07 +00:00
|
|
|
</MenuItem>
|
|
|
|
</Dropdown>
|
2022-04-08 13:48:36 +00:00
|
|
|
</SettingsItem>
|
2022-07-28 12:12:13 +00:00
|
|
|
<div style={{ display: this.state.customDisplay }}>
|
2023-01-21 12:10:40 +00:00
|
|
|
<SettingsItem title={variables.getMessage('modals.main.settings.sections.search.custom')} final={true}>
|
2022-07-28 12:12:13 +00:00
|
|
|
<TextField
|
2022-08-26 09:45:32 +00:00
|
|
|
label={variables.getMessage('modals.main.settings.sections.search.custom')}
|
2022-07-15 21:00:55 +00:00
|
|
|
value={this.state.customValue}
|
|
|
|
onInput={(e) => this.setState({ customValue: e.target.value })}
|
|
|
|
varient="outlined"
|
|
|
|
InputLabelProps={{ shrink: true }}
|
|
|
|
/>
|
2022-07-28 12:12:13 +00:00
|
|
|
<p style={{ marginTop: '0px' }}>
|
|
|
|
<span className="link" onClick={() => this.resetSearch()}>
|
2022-08-26 09:45:32 +00:00
|
|
|
{variables.getMessage('modals.main.settings.buttons.reset')}
|
2022-07-28 12:12:13 +00:00
|
|
|
</span>
|
|
|
|
</p>
|
|
|
|
</SettingsItem>
|
|
|
|
</div>
|
2021-03-22 22:17:52 +00:00
|
|
|
</>
|
2020-09-17 11:42:02 +00:00
|
|
|
);
|
|
|
|
}
|
2021-03-17 13:01:53 +00:00
|
|
|
}
|