diff --git a/client/src/components/Settings/Themer/ThemeBuilder/ThemeBuilder.tsx b/client/src/components/Settings/Themer/ThemeBuilder/ThemeBuilder.tsx index 0762f13..4ae2822 100644 --- a/client/src/components/Settings/Themer/ThemeBuilder/ThemeBuilder.tsx +++ b/client/src/components/Settings/Themer/ThemeBuilder/ThemeBuilder.tsx @@ -1,21 +1,69 @@ +import { useState } from 'react'; + +// Redux +import { useSelector } from 'react-redux'; +import { State } from '../../../../store/reducers'; + +// Other import { Theme } from '../../../../interfaces'; -import { Button } from '../../../UI'; + +// UI +import { Button, Modal } from '../../../UI'; import { ThemeGrid } from '../ThemeGrid/ThemeGrid'; import classes from './ThemeBuilder.module.css'; +import { ThemeCreator } from './ThemeCreator'; +import { ThemeEditor } from './ThemeEditor'; interface Props { themes: Theme[]; } export const ThemeBuilder = ({ themes }: Props): JSX.Element => { + const { + auth: { isAuthenticated }, + } = useSelector((state: State) => state); + + const [showModal, toggleShowModal] = useState(false); + const [isInEdit, toggleIsInEdit] = useState(false); + return (
+ {/* MODALS */} + toggleShowModal(!showModal)}> + {isInEdit ? ( + toggleShowModal(!showModal)} /> + ) : ( + toggleShowModal(!showModal)} /> + )} + + + {/* USER THEMES */} -
- - {themes.length && } -
+ {/* BUTTONS */} + {isAuthenticated && ( +
+ + + {themes.length && ( + + )} +
+ )}
); }; diff --git a/client/src/components/Settings/Themer/ThemeBuilder/ThemeCreator.module.css b/client/src/components/Settings/Themer/ThemeBuilder/ThemeCreator.module.css new file mode 100644 index 0000000..893095f --- /dev/null +++ b/client/src/components/Settings/Themer/ThemeBuilder/ThemeCreator.module.css @@ -0,0 +1,6 @@ +.ColorsContainer { + display: grid; + grid-template-columns: repeat(3, 1fr); + grid-gap: 10px; + margin-bottom: 20px; +} diff --git a/client/src/components/Settings/Themer/ThemeBuilder/ThemeCreator.tsx b/client/src/components/Settings/Themer/ThemeBuilder/ThemeCreator.tsx new file mode 100644 index 0000000..0d696e6 --- /dev/null +++ b/client/src/components/Settings/Themer/ThemeBuilder/ThemeCreator.tsx @@ -0,0 +1,117 @@ +import { ChangeEvent, FormEvent, useState } from 'react'; +import { useDispatch } from 'react-redux'; +import { bindActionCreators } from 'redux'; +import { actionCreators } from '../../../../store'; +import { Theme } from '../../../../interfaces'; +import { Button, InputGroup, ModalForm } from '../../../UI'; + +import classes from './ThemeCreator.module.css'; + +interface Props { + modalHandler: () => void; +} + +export const ThemeCreator = ({ modalHandler }: Props): JSX.Element => { + const { addTheme } = bindActionCreators(actionCreators, useDispatch()); + + const [formData, setFormData] = useState({ + name: '', + isCustom: true, + colors: { + primary: '#ffffff', + accent: '#ffffff', + background: '#ffffff', + }, + }); + + const inputChangeHandler = (e: ChangeEvent) => { + const { name, value } = e.target; + + setFormData({ + ...formData, + [name]: value, + }); + }; + + const setColor = ({ + target: { value, name }, + }: ChangeEvent) => { + setFormData({ + ...formData, + colors: { + ...formData.colors, + [name]: value, + }, + }); + }; + + const formHandler = (e: FormEvent) => { + e.preventDefault(); + + // add new theme + addTheme(formData); + + // close modal + modalHandler(); + + // clear theme name + setFormData({ ...formData, name: '' }); + }; + + return ( + + + + inputChangeHandler(e)} + /> + + +
+ + + setColor(e)} + /> + + + + + setColor(e)} + /> + + + + + setColor(e)} + /> + +
+ + +
+ ); +}; diff --git a/client/src/components/Settings/Themer/ThemeBuilder/ThemeEditor.tsx b/client/src/components/Settings/Themer/ThemeBuilder/ThemeEditor.tsx new file mode 100644 index 0000000..b899049 --- /dev/null +++ b/client/src/components/Settings/Themer/ThemeBuilder/ThemeEditor.tsx @@ -0,0 +1,13 @@ +import { ModalForm } from '../../../UI'; + +interface Props { + modalHandler: () => void; +} + +export const ThemeEditor = (props: Props): JSX.Element => { + return ( + {}} modalHandler={props.modalHandler}> +

edit

+
+ ); +}; diff --git a/client/src/components/Settings/Themer/Themer.tsx b/client/src/components/Settings/Themer/Themer.tsx index 3bcaa2e..5a7ff06 100644 --- a/client/src/components/Settings/Themer/Themer.tsx +++ b/client/src/components/Settings/Themer/Themer.tsx @@ -4,6 +4,7 @@ import { ChangeEvent, FormEvent, Fragment, useEffect, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { bindActionCreators } from 'redux'; import { actionCreators } from '../../../store'; +import { State } from '../../../store/reducers'; // Typescript import { Theme, ThemeSettingsForm } from '../../../interfaces'; @@ -14,7 +15,6 @@ import { ThemeBuilder } from './ThemeBuilder/ThemeBuilder'; import { ThemeGrid } from './ThemeGrid/ThemeGrid'; // Other -import { State } from '../../../store/reducers'; import { inputHandler, parseThemeToPAB, @@ -82,7 +82,7 @@ export const Themer = (): JSX.Element => {
- +