// React import { useState, useEffect, FormEvent, ChangeEvent, Fragment } from 'react'; import { useDispatch, useSelector } from 'react-redux'; // Typescript import { Query, SearchForm } from '../../../interfaces'; // Components import { CustomQueries } from './CustomQueries/CustomQueries'; // UI import { Button, SettingsHeadline, InputGroup } from '../../UI'; // Utils import { inputHandler, searchSettingsTemplate } from '../../../utility'; // Data import { queries } from '../../../utility/searchQueries.json'; // Redux import { State } from '../../../store/reducers'; import { bindActionCreators } from 'redux'; import { actionCreators } from '../../../store'; export const SearchSettings = (): JSX.Element => { const { loading, customQueries, config } = useSelector( (state: State) => state.config ); const dispatch = useDispatch(); const { updateConfig } = bindActionCreators(actionCreators, dispatch); // Initial state const [formData, setFormData] = useState(searchSettingsTemplate); // Get config useEffect(() => { setFormData({ ...config, }); }, [loading]); // Form handler const formSubmitHandler = async (e: FormEvent) => { e.preventDefault(); // Save settings await updateConfig(formData); }; // Input handler const inputChangeHandler = ( e: ChangeEvent, options?: { isNumber?: boolean; isBool?: boolean } ) => { inputHandler({ e, options, setStateHandler: setFormData, state: formData, }); }; return ( {/* GENERAL SETTINGS */}
formSubmitHandler(e)} style={{ marginBottom: '30px' }} > {/* CUSTOM QUERIES */}
); };