2017-04-19 03:06:51 +08:00
|
|
|
import { Tracker } from 'meteor/tracker';
|
2018-11-23 22:14:48 +08:00
|
|
|
import React, { PureComponent } from 'react';
|
2017-04-19 03:06:51 +08:00
|
|
|
|
2017-06-03 03:25:02 +08:00
|
|
|
const currentModal = {
|
2017-04-19 03:06:51 +08:00
|
|
|
component: null,
|
2017-06-03 03:25:02 +08:00
|
|
|
tracker: new Tracker.Dependency(),
|
2017-04-19 03:06:51 +08:00
|
|
|
};
|
|
|
|
|
2020-03-03 04:49:15 +08:00
|
|
|
export const showModal = (component) => {
|
2017-04-19 03:06:51 +08:00
|
|
|
if (currentModal.component !== component) {
|
|
|
|
currentModal.component = component;
|
|
|
|
currentModal.tracker.changed();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getModal = () => {
|
|
|
|
currentModal.tracker.depend();
|
|
|
|
return currentModal.component;
|
|
|
|
};
|
|
|
|
|
2021-03-07 22:12:49 +08:00
|
|
|
export const withModalMounter = ComponentToWrap => class ModalMounterWrapper extends PureComponent {
|
|
|
|
static mount(modalComponent) {
|
|
|
|
showModal(null);
|
|
|
|
// defer the execution to a subsequent event loop
|
|
|
|
setTimeout(() => showModal(modalComponent), 0);
|
|
|
|
}
|
2017-04-19 03:06:51 +08:00
|
|
|
|
2021-03-07 22:12:49 +08:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<ComponentToWrap
|
2017-04-19 03:06:51 +08:00
|
|
|
{...this.props}
|
2017-10-11 06:08:51 +08:00
|
|
|
mountModal={ModalMounterWrapper.mount}
|
2021-03-07 22:12:49 +08:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|