1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-19 03:29:37 +02:00
flame/client/src/components/Settings/Themer/ThemeBuilder/ThemeBuilder.tsx

89 lines
2.2 KiB
TypeScript
Raw Normal View History

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