From 3af06edb95fa3c0e7c0106dbc25657e7f8fecd41 Mon Sep 17 00:00:00 2001 From: sadan4 <117494111+sadan4@users.noreply.github.com> Date: Sat, 4 Jan 2025 00:01:58 -0500 Subject: [PATCH] ConsoleShortcuts: Add openModal and openModalLazy (#3118) --- src/plugins/consoleShortcuts/index.ts | 3 +++ src/utils/modal.tsx | 23 ++++++++++------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/plugins/consoleShortcuts/index.ts b/src/plugins/consoleShortcuts/index.ts index f10335e3c..516522a45 100644 --- a/src/plugins/consoleShortcuts/index.ts +++ b/src/plugins/consoleShortcuts/index.ts @@ -20,6 +20,7 @@ import { Devs } from "@utils/constants"; import { getCurrentChannel, getCurrentGuild } from "@utils/discord"; import { runtimeHashMessageKey } from "@utils/intlHash"; import { SYM_LAZY_CACHED, SYM_LAZY_GET } from "@utils/lazy"; +import { ModalAPI } from "@utils/modal"; import { relaunch } from "@utils/native"; import { canonicalizeMatch, canonicalizeReplace, canonicalizeReplacement } from "@utils/patches"; import definePlugin, { PluginNative, StartAt } from "@utils/types"; @@ -144,6 +145,8 @@ function makeShortcuts() { me: { getter: () => Common.UserStore.getCurrentUser(), preload: false }, meId: { getter: () => Common.UserStore.getCurrentUser().id, preload: false }, messages: { getter: () => Common.MessageStore.getMessages(Common.SelectedChannelStore.getChannelId()), preload: false }, + openModal: { getter: () => ModalAPI.openModal }, + openModalLazy: { getter: () => ModalAPI.openModalLazy }, Stores: { getter: () => Object.fromEntries( diff --git a/src/utils/modal.tsx b/src/utils/modal.tsx index a11cb3cc5..c399d198e 100644 --- a/src/utils/modal.tsx +++ b/src/utils/modal.tsx @@ -141,35 +141,32 @@ export const ModalContent = LazyComponent(() => Modals.ModalContent); export const ModalFooter = LazyComponent(() => Modals.ModalFooter); export const ModalCloseButton = LazyComponent(() => Modals.ModalCloseButton); -const ModalAPI = findByPropsLazy("openModalLazy"); +export const ModalAPI = findByPropsLazy("openModalLazy"); /** * Wait for the render promise to resolve, then open a modal with it. * This is equivalent to render().then(openModal) * You should use the Modal components exported by this file */ -export function openModalLazy(render: () => Promise, options?: ModalOptions & { contextKey?: string; }): Promise { - return ModalAPI.openModalLazy(render, options); -} +export const openModalLazy: (render: () => Promise, options?: ModalOptions & { contextKey?: string; }) => Promise + = proxyLazyWebpack(() => ModalAPI.openModalLazy); /** * Open a Modal with the given render function. * You should use the Modal components exported by this file */ -export function openModal(render: RenderFunction, options?: ModalOptions, contextKey?: string): string { - return ModalAPI.openModal(render, options, contextKey); -} +export const openModal: (render: RenderFunction, options?: ModalOptions, contextKey?: string) => string + = proxyLazyWebpack(() => ModalAPI.openModal); /** * Close a modal by its key */ -export function closeModal(modalKey: string, contextKey?: string): void { - return ModalAPI.closeModal(modalKey, contextKey); -} +export const closeModal: (modalKey: string, contextKey?: string) => void + = proxyLazyWebpack(() => ModalAPI.closeModal); /** * Close all open modals */ -export function closeAllModals(): void { - return ModalAPI.closeAllModals(); -} +export const closeAllModals: () => void + = proxyLazyWebpack(() => ModalAPI.closeAllModals); +