insomnia/packages/insomnia-app/app/ui/components/modals/index.js

45 lines
942 B
JavaScript
Raw Normal View History

import PromptModal from './prompt-modal';
2017-07-17 22:37:24 +00:00
import AlertModal from './alert-modal';
2017-09-17 14:04:46 +00:00
import ErrorModal from './error-modal';
const modals = {};
2018-06-25 17:42:50 +00:00
export function registerModal(instance) {
if (instance === null) {
// Modal was unmounted
return;
}
modals[instance.constructor.name] = instance;
}
2018-06-25 17:42:50 +00:00
export function showPrompt(config) {
2017-11-01 14:13:51 +00:00
return showModal(PromptModal, config);
}
2018-06-25 17:42:50 +00:00
export function showAlert(config) {
2017-11-01 14:13:51 +00:00
return showModal(AlertModal, config);
2017-07-17 22:37:24 +00:00
}
2018-06-25 17:42:50 +00:00
export function showError(config) {
2018-08-01 20:08:33 +00:00
try {
return showModal(ErrorModal, config);
} catch (err) {
console.log('[modal] Cannot show modal', err, config);
}
2017-09-17 14:04:46 +00:00
}
2018-06-25 17:42:50 +00:00
export function showModal(modalCls, ...args) {
return _getModal(modalCls).show(...args);
}
2018-06-25 17:42:50 +00:00
export function hideAllModals() {
2017-03-29 02:21:49 +00:00
for (const key of Object.keys(modals)) {
const modal = modals[key];
modal.hide && modal.hide();
}
}
2018-06-25 17:42:50 +00:00
function _getModal(modalCls) {
return modals[modalCls.name];
}