Add modal api
This commit is contained in:
parent
4f531b3634
commit
e52225304e
2 changed files with 35 additions and 0 deletions
|
@ -7,6 +7,7 @@ import { Button, ButtonProps, Flex, Switch, Forms, React } from "../webpack/comm
|
||||||
import ErrorBoundary from "./ErrorBoundary";
|
import ErrorBoundary from "./ErrorBoundary";
|
||||||
import { startPlugin } from "../plugins";
|
import { startPlugin } from "../plugins";
|
||||||
import { stopPlugin } from '../plugins/index';
|
import { stopPlugin } from '../plugins/index';
|
||||||
|
import { openModal, closeModal } from '../utils/modal';
|
||||||
|
|
||||||
export default ErrorBoundary.wrap(function Settings(props) {
|
export default ErrorBoundary.wrap(function Settings(props) {
|
||||||
const [settingsDir, , settingsDirPending] = useAwaiter(() => VencordNative.ipc.invoke<string>(IpcEvents.GET_SETTINGS_DIR), "Loading...");
|
const [settingsDir, , settingsDirPending] = useAwaiter(() => VencordNative.ipc.invoke<string>(IpcEvents.GET_SETTINGS_DIR), "Loading...");
|
||||||
|
|
34
src/utils/modal.tsx
Normal file
34
src/utils/modal.tsx
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
import Components from "discord-types/components";
|
||||||
|
import { waitFor } from "../webpack";
|
||||||
|
|
||||||
|
let Modal: Components.Modal;
|
||||||
|
let modals: any;
|
||||||
|
|
||||||
|
waitFor("openModalLazy", m => modals = m);
|
||||||
|
waitFor("ModalRoot", m => Modal = m);
|
||||||
|
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
export function openModal(Component: React.ComponentType) {
|
||||||
|
let key = `Vencord${modalId++}`;
|
||||||
|
modals.openModal(props =>
|
||||||
|
<Modal.ModalRoot {...props}>
|
||||||
|
<Component />
|
||||||
|
</Modal.ModalRoot>
|
||||||
|
, { modalKey: key });
|
||||||
|
|
||||||
|
return key;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
modals.closeModal(key);
|
||||||
|
}
|
Loading…
Reference in a new issue