mue/src/components/modals/main/Main.jsx

73 lines
2.0 KiB
React
Raw Normal View History

import variables from 'modules/variables';
import { Suspense, lazy, useState } from 'react';
2022-10-30 16:56:26 +00:00
import { memo } from 'react';
import { MdClose } from 'react-icons/md';
2020-10-15 14:23:01 +00:00
2021-03-23 09:44:57 +00:00
import Tabs from './tabs/backend/Tabs';
2021-03-20 12:55:20 +00:00
import './scss/index.scss';
import Tooltip from '../../helpers/tooltip/Tooltip';
2021-03-20 12:55:20 +00:00
2021-04-21 18:35:33 +00:00
// Lazy load all the tabs instead of the modal itself
2021-08-14 19:10:48 +00:00
const Settings = lazy(() => import('./tabs/Settings'));
const Addons = lazy(() => import('./tabs/Addons'));
const Marketplace = lazy(() => import('./tabs/Marketplace'));
const renderLoader = (current) => (
<Tabs current={current}>
<div label={variables.getMessage('modals.main.loading')}>
<div className="emptyItems">
<div className="emptyMessage">
<div className="loaderHolder">
<div id="loader"></div>
<span className="subtitle">{variables.getMessage('modals.main.loading')}</span>
</div>
</div>
</div>
</div>
<div label="" style={{ display: 'none' }}></div>
</Tabs>
);
2022-10-30 16:56:26 +00:00
function MainModal({ modalClose }) {
const [currentTab, setCurrentTab] = useState(0);
const changeTab = (type) => {
switch (type) {
case 'settings':
setCurrentTab(<Settings changeTab={changeTab} />);
break;
case 'addons':
setCurrentTab(<Addons changeTab={changeTab} />);
break;
case 'marketplace':
setCurrentTab(<Marketplace changeTab={changeTab} />);
break;
default:
break;
}
};
if (currentTab === 0) {
setCurrentTab(<Settings changeTab={changeTab} />);
}
2021-03-13 18:15:57 +00:00
return (
<div className="frame">
<Tooltip
style={{ position: 'absolute', top: '1rem', right: '1rem' }}
title={variables.getMessage('modals.welcome.buttons.close')}
key="closeTooltip"
>
<span className="closeModal" onClick={modalClose}>
<MdClose />
</span>
</Tooltip>
<Suspense fallback={renderLoader(currentTab)}>{currentTab}</Suspense>
</div>
2021-03-13 18:15:57 +00:00
);
}
2022-10-30 16:56:26 +00:00
2022-11-06 11:59:59 +00:00
export default memo(MainModal);