mue/src/features/modals/Modals.jsx

111 lines
3.0 KiB
React
Raw Normal View History

import variables from 'config/variables';
import { PureComponent } from 'react';
2021-08-15 21:28:37 +00:00
import Modal from 'react-modal';
import Main from './main/Main';
2021-03-20 12:55:20 +00:00
import Navbar from '../widgets/navbar/Navbar';
import Preview from '../helpers/preview/Preview';
2021-03-20 12:55:20 +00:00
import EventBus from 'utils/eventbus';
2021-03-20 12:55:20 +00:00
import Welcome from './welcome/Welcome';
2021-03-20 12:55:20 +00:00
2021-08-14 19:10:48 +00:00
export default class Modals extends PureComponent {
2021-03-23 13:10:34 +00:00
constructor() {
super();
2021-03-20 12:55:20 +00:00
this.state = {
mainModal: false,
updateModal: false,
welcomeModal: false,
appsModal: false,
preview: false,
2021-03-20 12:55:20 +00:00
};
}
componentDidMount() {
if (
localStorage.getItem('showWelcome') === 'true' &&
window.location.search !== '?nointro=true'
) {
2021-03-20 12:55:20 +00:00
this.setState({
welcomeModal: true,
2021-03-20 12:55:20 +00:00
});
2021-09-28 22:04:04 +00:00
variables.stats.postEvent('modal', 'Opened welcome');
2021-03-20 12:55:20 +00:00
}
2021-09-03 11:31:12 +00:00
if (window.location.search === '?nointro=true') {
if (localStorage.getItem('showWelcome') === 'true') {
localStorage.setItem('showWelcome', false);
2023-03-16 11:11:18 +00:00
EventBus.emit('refresh', 'widgets');
EventBus.emit('refresh', 'backgroundwelcome');
2021-09-03 11:31:12 +00:00
}
}
// hide refresh reminder once the user has refreshed the page
localStorage.setItem('showReminder', false);
2021-03-20 12:55:20 +00:00
}
closeWelcome() {
localStorage.setItem('showWelcome', false);
this.setState({
welcomeModal: false,
2021-03-20 12:55:20 +00:00
});
2023-03-16 11:11:18 +00:00
EventBus.emit('refresh', 'widgetsWelcomeDone');
EventBus.emit('refresh', 'widgets');
EventBus.emit('refresh', 'backgroundwelcome');
2021-06-21 16:42:14 +00:00
}
previewWelcome() {
localStorage.setItem('showWelcome', false);
localStorage.setItem('welcomePreview', true);
this.setState({
welcomeModal: false,
preview: true,
});
2023-03-16 11:11:18 +00:00
EventBus.emit('refresh', 'widgetsWelcome');
}
2021-06-21 16:42:14 +00:00
toggleModal(type, action) {
this.setState({
[type]: action,
2021-06-21 16:42:14 +00:00
});
2021-06-21 22:03:47 +00:00
if (action !== false) {
2021-09-28 22:04:04 +00:00
variables.stats.postEvent('modal', `Opened ${type.replace('Modal', '')}`);
2021-06-21 22:03:47 +00:00
}
2021-03-20 12:55:20 +00:00
}
render() {
return (
<>
{this.state.welcomeModal === false && (
<Navbar openModal={(modal) => this.toggleModal(modal, true)} />
)}
<Modal
closeTimeoutMS={300}
id="modal"
onRequestClose={() => this.toggleModal('mainModal', false)}
isOpen={this.state.mainModal}
className="Modal mainModal"
overlayClassName="Overlay"
ariaHideApp={false}
>
<Main modalClose={() => this.toggleModal('mainModal', false)} />
2022-04-07 20:49:43 +00:00
</Modal>
<Modal
closeTimeoutMS={300}
onRequestClose={() => this.closeWelcome()}
isOpen={this.state.welcomeModal}
className="Modal welcomemodal mainModal"
2022-08-07 17:36:56 +00:00
overlayClassName="Overlay mainModal"
shouldCloseOnOverlayClick={false}
ariaHideApp={false}
>
<Welcome modalClose={() => this.closeWelcome()} modalSkip={() => this.previewWelcome()} />
</Modal>
{this.state.preview && <Preview setup={() => window.location.reload()} />}
</>
2021-03-20 12:55:20 +00:00
);
}
}