import { useState, useEffect } from 'react'; // Redux import { useSelector, useDispatch } from 'react-redux'; import { bindActionCreators } from 'redux'; import { actionCreators } from '../../../../store'; import { State } from '../../../../store/reducers'; // Other import { Theme } from '../../../../interfaces'; // 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 }, theme: { themeInEdit }, } = useSelector((state: State) => state); const { editTheme } = bindActionCreators(actionCreators, useDispatch()); const [showModal, toggleShowModal] = useState(false); const [isInEdit, toggleIsInEdit] = useState(false); useEffect(() => { if (themeInEdit) { toggleIsInEdit(false); toggleShowModal(true); } }, [themeInEdit]); return (
{/* MODALS */} toggleShowModal(!showModal)} cb={() => editTheme(null)} > {isInEdit ? ( toggleShowModal(!showModal)} /> ) : ( toggleShowModal(!showModal)} /> )} {/* USER THEMES */} {/* BUTTONS */} {isAuthenticated && (
{themes.length ? ( ) : ( <> )}
)}
); };