// React import { useState, useEffect, FormEvent, ChangeEvent, Fragment } from 'react'; import { useDispatch, useSelector } from 'react-redux'; // Typescript import { Query, GeneralForm } from '../../../interfaces'; // Components import { CustomQueries } from './CustomQueries/CustomQueries'; // UI import { Button, SettingsHeadline, InputGroup } from '../../UI'; // Utils import { inputHandler, generalSettingsTemplate } 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 GeneralSettings = (): JSX.Element => { const { config: { loading, customQueries, config }, bookmarks: { categories }, } = useSelector((state: State) => state); const dispatch = useDispatch(); const { updateConfig, sortApps, sortCategories, sortBookmarks } = bindActionCreators(actionCreators, dispatch); // Initial state const [formData, setFormData] = useState( generalSettingsTemplate ); // Get config useEffect(() => { setFormData({ ...config, }); }, [loading]); // Form handler const formSubmitHandler = async (e: FormEvent) => { e.preventDefault(); // Save settings await updateConfig(formData); // Sort entities with new settings if (formData.useOrdering !== config.useOrdering) { sortApps(); sortCategories(); for (let { id } of categories) { sortBookmarks(id); } } }; // Input handler const inputChangeHandler = ( e: ChangeEvent, options?: { isNumber?: boolean; isBool?: boolean } ) => { inputHandler({ e, options, setStateHandler: setFormData, state: formData, }); }; return (
formSubmitHandler(e)} style={{ marginBottom: '30px' }} > {/* === GENERAL OPTIONS === */} {/* SORT TYPE */} {/* === APPS OPTIONS === */} {/* PIN APPS */} {/* APPS OPPENING */} {/* === BOOKMARKS OPTIONS === */} {/* PIN CATEGORIES */} {/* BOOKMARKS OPPENING */} {/* === SEARCH OPTIONS === */} {formData.defaultSearchProvider === 'l' && ( Will be used when "Local search" is primary search provider and there are not any local results )} {/* CUSTOM QUERIES */}
); };