2022-03-24 16:07:14 +01:00
|
|
|
import { useState } from 'react';
|
|
|
|
|
|
|
|
// Redux
|
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import { State } from '../../../../store/reducers';
|
|
|
|
|
|
|
|
// Other
|
2022-03-23 16:13:34 +01:00
|
|
|
import { Theme } from '../../../../interfaces';
|
2022-03-24 16:07:14 +01:00
|
|
|
|
|
|
|
// UI
|
|
|
|
import { Button, Modal } from '../../../UI';
|
2022-03-23 16:13:34 +01:00
|
|
|
import { ThemeGrid } from '../ThemeGrid/ThemeGrid';
|
|
|
|
import classes from './ThemeBuilder.module.css';
|
2022-03-24 16:07:14 +01:00
|
|
|
import { ThemeCreator } from './ThemeCreator';
|
|
|
|
import { ThemeEditor } from './ThemeEditor';
|
2022-03-23 16:13:34 +01:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
themes: Theme[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export const ThemeBuilder = ({ themes }: Props): JSX.Element => {
|
2022-03-24 16:07:14 +01:00
|
|
|
const {
|
|
|
|
auth: { isAuthenticated },
|
|
|
|
} = useSelector((state: State) => state);
|
|
|
|
|
|
|
|
const [showModal, toggleShowModal] = useState(false);
|
|
|
|
const [isInEdit, toggleIsInEdit] = useState(false);
|
|
|
|
|
2022-03-23 16:13:34 +01:00
|
|
|
return (
|
|
|
|
<div className={classes.ThemeBuilder}>
|
2022-03-24 16:07:14 +01:00
|
|
|
{/* MODALS */}
|
|
|
|
<Modal isOpen={showModal} setIsOpen={() => toggleShowModal(!showModal)}>
|
|
|
|
{isInEdit ? (
|
|
|
|
<ThemeEditor modalHandler={() => toggleShowModal(!showModal)} />
|
|
|
|
) : (
|
|
|
|
<ThemeCreator modalHandler={() => toggleShowModal(!showModal)} />
|
|
|
|
)}
|
|
|
|
</Modal>
|
|
|
|
|
|
|
|
{/* USER THEMES */}
|
2022-03-23 16:13:34 +01:00
|
|
|
<ThemeGrid themes={themes} />
|
|
|
|
|
2022-03-24 16:07:14 +01:00
|
|
|
{/* BUTTONS */}
|
|
|
|
{isAuthenticated && (
|
|
|
|
<div className={classes.Buttons}>
|
|
|
|
<Button
|
|
|
|
click={() => {
|
|
|
|
toggleIsInEdit(false);
|
|
|
|
toggleShowModal(!showModal);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Create new theme
|
|
|
|
</Button>
|
|
|
|
|
|
|
|
{themes.length && (
|
|
|
|
<Button
|
|
|
|
click={() => {
|
|
|
|
toggleIsInEdit(true);
|
|
|
|
toggleShowModal(!showModal);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Edit user themes
|
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)}
|
2022-03-23 16:13:34 +01:00
|
|
|
</div>
|
|
|
|
);
|
2022-03-23 13:02:32 +01:00
|
|
|
};
|