import { useState, useEffect, ChangeEvent, FormEvent } from 'react'; // Redux import { useDispatch, useSelector } from 'react-redux'; import { State } from '../../../store/reducers'; import { bindActionCreators } from 'redux'; import { actionCreators } from '../../../store'; // Typescript import { OtherSettingsForm } from '../../../interfaces'; // UI import { InputGroup, Button, SettingsHeadline } from '../../UI'; // Utils import { otherSettingsTemplate, inputHandler } from '../../../utility'; export const UISettings = (): JSX.Element => { const { config: { loading, config }, bookmarks: { categories }, } = useSelector((state: State) => state); const dispatch = useDispatch(); const { updateConfig, sortApps, sortCategories, sortBookmarks } = bindActionCreators(actionCreators, dispatch); // Initial state const [formData, setFormData] = useState( otherSettingsTemplate ); // Get config useEffect(() => { setFormData({ ...config, }); }, [loading]); // Form handler const formSubmitHandler = async (e: FormEvent) => { e.preventDefault(); // Save settings await updateConfig(formData); // Update local page title document.title = formData.customTitle; // 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)}> {/* === OTHER OPTIONS === */} {/* PAGE TITLE */} inputChangeHandler(e)} /> {/* === HEADER OPTIONS === */} {/* HIDE HEADER */} {/* HIDE DATE */} {/* HIDE TIME */} {/* DATE FORMAT */} {/* CUSTOM GREETINGS */} inputChangeHandler(e)} /> Greetings must be separated with semicolon. Only 4 messages can be used {/* CUSTOM DAYS */} inputChangeHandler(e)} /> Names must be separated with semicolon {/* CUSTOM MONTHS */} inputChangeHandler(e)} /> Names must be separated with semicolon {/* === BEAHVIOR OPTIONS === */} {/* PIN APPS */} {/* PIN CATEGORIES */} {/* SORT TYPE */} {/* APPS OPPENING */} {/* BOOKMARKS OPPENING */} {/* === MODULES OPTIONS === */} {/* HIDE APPS */} {/* HIDE CATEGORIES */} ); };