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 { UISettingsForm } from '../../../interfaces'; // UI import { InputGroup, Button, SettingsHeadline } from '../../UI'; // Utils import { uiSettingsTemplate, inputHandler } from '../../../utility'; export const UISettings = (): JSX.Element => { const { loading, config } = useSelector((state: State) => state.config); const dispatch = useDispatch(); const { updateConfig } = bindActionCreators(actionCreators, dispatch); // Initial state const [formData, setFormData] = useState(uiSettingsTemplate); // 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; }; // 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)} /> {/* === SEARCH OPTIONS === */} {/* HIDE SEARCHBAR */} {/* AUTOFOCUS SEARCHBAR */} {/* === HEADER OPTIONS === */} {/* HIDE HEADER */} {/* HIDE DATE */} {/* HIDE TIME */} {/* DATE FORMAT */} {/* CUSTOM GREETINGS */} inputChangeHandler(e)} /> Greetings must be separated with semicolon. All 4 messages must be filled, even if they are the same {/* CUSTOM DAYS */} inputChangeHandler(e)} /> Names must be separated with semicolon {/* CUSTOM MONTHS */} inputChangeHandler(e)} /> Names must be separated with semicolon {/* === SECTIONS OPTIONS === */} {/* HIDE APPS */} {/* HIDE CATEGORIES */} ); };