2022-10-14 15:34:35 -04:00
|
|
|
import { filters } from "../webpack";
|
|
|
|
import { lazyWebpack } from "./misc";
|
|
|
|
import { mapMangledModuleLazy } from "../webpack/webpack";
|
2022-09-30 21:58:07 -04:00
|
|
|
|
2022-10-14 15:34:35 -04:00
|
|
|
const ModalRoot = lazyWebpack(filters.byCode("headerIdIsManaged:"));
|
|
|
|
const Modals = mapMangledModuleLazy("onCloseRequest:null!=", {
|
|
|
|
openModal: filters.byCode("onCloseRequest:null!="),
|
|
|
|
closeModal: filters.byCode("onCloseCallback&&")
|
|
|
|
});
|
2022-09-08 15:47:53 -04:00
|
|
|
|
|
|
|
let modalId = 1337;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open a modal
|
|
|
|
* @param Component The component to render in the modal
|
|
|
|
* @returns The key of this modal. This can be used to close the modal later with closeModal
|
|
|
|
*/
|
2022-09-08 16:25:21 -04:00
|
|
|
export function openModal(Component: React.ComponentType, modalProps: Record<string, any>) {
|
2022-09-08 15:47:53 -04:00
|
|
|
let key = `Vencord${modalId++}`;
|
2022-10-14 15:34:35 -04:00
|
|
|
Modals.openModal(props => (
|
|
|
|
<ModalRoot {...props} {...modalProps}>
|
2022-09-08 15:47:53 -04:00
|
|
|
<Component />
|
2022-10-14 15:34:35 -04:00
|
|
|
</ModalRoot>
|
2022-10-05 18:42:58 -04:00
|
|
|
), { modalKey: key });
|
2022-09-08 15:47:53 -04:00
|
|
|
|
|
|
|
return key;
|
2022-10-08 14:36:57 -04:00
|
|
|
}
|
2022-09-08 15:47:53 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Close a modal by key. The id you need for this is returned by openModal.
|
|
|
|
* @param key The key of the modal to close
|
|
|
|
*/
|
|
|
|
export function closeModal(key: string) {
|
2022-10-14 15:34:35 -04:00
|
|
|
Modals.closeModal(key);
|
2022-09-16 16:59:34 -04:00
|
|
|
}
|