mue/src/components/modals/settings/sections/Search.jsx

80 lines
2.7 KiB
React
Raw Normal View History

2020-09-17 11:42:02 +00:00
import React from 'react';
2021-01-17 18:07:26 +00:00
2020-09-22 14:43:09 +00:00
import { toast } from 'react-toastify';
2021-01-17 18:07:26 +00:00
2020-10-27 14:59:45 +00:00
import Dropdown from '../Dropdown';
2020-11-29 14:32:08 +00:00
import Checkbox from '../Checkbox';
2020-09-22 14:43:09 +00:00
2020-11-29 14:32:08 +00:00
const searchEngines = require('../../../widgets/search/search_engines.json');
2020-09-17 11:42:02 +00:00
export default class SearchSettings extends React.PureComponent {
2020-09-22 14:43:09 +00:00
resetSearch() {
localStorage.removeItem('customSearchEngine');
document.getElementById('customSearchEngine').value = '';
2021-02-08 17:29:07 +00:00
2020-09-22 14:43:09 +00:00
toast(this.props.toastLanguage.reset);
}
2020-09-18 11:58:37 +00:00
componentDidMount() {
const searchEngine = localStorage.getItem('searchEngine');
2021-01-16 22:43:46 +00:00
if (searchEngine === 'custom') {
2020-09-18 11:58:37 +00:00
const input = document.getElementById('searchEngineInput');
2021-01-16 22:43:46 +00:00
2020-09-18 11:58:37 +00:00
input.style.display = 'block';
input.enabled = 'true';
2021-01-16 22:43:46 +00:00
2020-09-18 11:58:37 +00:00
document.getElementById('customSearchEngine').value = localStorage.getItem('customSearchEngine');
2021-01-16 22:43:46 +00:00
} else {
localStorage.removeItem('customSearchEngine');
}
2020-09-19 13:53:33 +00:00
document.getElementById('searchEngine').value = searchEngine;
2020-09-18 11:58:37 +00:00
}
2021-02-26 12:29:57 +00:00
componentDidUpdate() {
if (document.getElementById('searchEngineInput').enabled === 'true') {
const input = document.getElementById('customSearchEngine').value;
if (input) {
localStorage.setItem('searchEngine', 'custom');
localStorage.setItem('customSearchEngine', input);
}
}
}
setSearchEngine(input) {
const searchEngineInput = document.getElementById('searchEngineInput');
if (input === 'custom') {
searchEngineInput.enabled = 'true';
searchEngineInput.style.display = 'block';
} else {
searchEngineInput.style.display = 'none';
searchEngineInput.enabled = 'false';
localStorage.setItem('searchEngine', input);
}
}
2020-09-17 11:42:02 +00:00
render() {
return (
<div className='section'>
<h2>Search</h2>
2021-03-01 12:06:02 +00:00
<Checkbox name='voiceSearch' text={this.props.language.voice_search} />
2020-10-27 14:59:45 +00:00
<ul>
2021-03-01 12:06:02 +00:00
<Dropdown label={this.props.language.search_engine}
2020-10-27 14:59:45 +00:00
name='searchEngine'
id='searchEngine'
2021-02-26 12:29:57 +00:00
onChange={() => this.setSearchEngine(document.getElementById('searchEngine').value)} >
2020-10-27 14:59:45 +00:00
{searchEngines.map((engine) =>
<option key={engine.name} className='choices' value={engine.settingsName}>{engine.name}</option>
)}
<option className='choices' value='custom'>Custom</option>
</Dropdown>
</ul>
<ul id='searchEngineInput' style={{ display: 'none' }}>
2021-03-01 12:06:02 +00:00
<p style={{ 'marginTop': '0px' }}>{this.props.language.custom} <span className='modalLink' onClick={() => this.resetSearch()}>{this.props.language.reset}</span></p>
2020-10-27 14:59:45 +00:00
<input type='text' id='customSearchEngine'></input>
</ul>
</div>
2020-09-17 11:42:02 +00:00
);
}
}