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 { loading, config } = useSelector((state: State) => state.config); const dispatch = useDispatch(); const { updateConfig, sortApps, sortCategories } = 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 apps and categories with new settings sortApps(); sortCategories(); }; // 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 */} ); };