Revert "Fixes"

This reverts commit 6fc7fc9f97.
This commit is contained in:
thororen1234 2024-10-22 14:45:56 -04:00
parent a7a722dab9
commit 2837028793
8 changed files with 47 additions and 51 deletions

View file

@ -17,10 +17,10 @@
*/
import { MessageObject } from "@api/MessageEvents";
import { ChannelStore, ComponentDispatch, Constants, FluxDispatcher, GuildStore, InviteActions, MessageActions, PrivateChannelsStore, RestAPI, SelectedChannelStore, SelectedGuildStore, UserProfileActions, UserProfileStore, UserSettingsActionCreators, UserUtils } from "@webpack/common";
import { ChannelStore, ComponentDispatch, Constants, FluxDispatcher, GuildStore, InviteActions, MaskedLink, MessageActions, ModalImageClasses, PrivateChannelsStore, RestAPI, SelectedChannelStore, SelectedGuildStore, UserProfileActions, UserProfileStore, UserSettingsActionCreators, UserUtils } from "@webpack/common";
import { Channel, Guild, Message, User } from "discord-types/general";
import { MediaData, MediaModal, openModal } from "./modal";
import { ImageModal, ModalRoot, ModalSize, openModal } from "./modal";
/**
* Open the invite modal
@ -108,22 +108,25 @@ export function sendMessage(
return MessageActions.sendMessage(channelId, messageData, waitForChannelReady, extra);
}
/**
*
* @param media The url of the media or its data
* @param mediaModalProps Additional props for the image modal
*/
export function openMediaModal(media: string | MediaData, mediaModalProps?: Partial<React.ComponentProps<MediaModal>>): string {
media = typeof media === "string" ? { url: media } : media;
media.original ??= media.url;
media.type ??= "IMAGE";
export function openImageModal(url: string, props?: Partial<React.ComponentProps<ImageModal>>): string {
return openModal(modalProps => (
<MediaModal
<ModalRoot
{...modalProps}
{...mediaModalProps}
shouldAnimateCarousel
items={[media]}
/>
className={ModalImageClasses.modal}
size={ModalSize.DYNAMIC}>
<ImageModal
className={ModalImageClasses.image}
original={url}
placeholder={url}
src={url}
renderLinkComponent={props => <MaskedLink {...props} />}
// Don't render forward message button
renderForwardComponent={() => null}
shouldHideMediaOptions={false}
shouldAnimate
{...props}
/>
</ModalRoot>
));
}

View file

@ -101,31 +101,25 @@ export const Modals = findByPropsLazy("ModalRoot", "ModalCloseButton") as {
}>;
};
// @TODO Type this
export type MediaData = {
url: string;
original?: string;
type?: string;
alt?: string;
export type ImageModal = ComponentType<{
className?: string;
src: string;
placeholder: string;
original: string;
width?: number;
height?: number;
animated?: boolean;
responsive?: boolean;
renderLinkComponent(props: any): ReactNode;
renderForwardComponent(props: any): ReactNode;
maxWidth?: number;
maxHeight?: number;
} & Record<PropertyKey, any>;
export type MediaModal = ComponentType<{
onClose?: () => void;
items: MediaData[];
startingIndex?: number;
onIndexChange?: (...args: any[]) => void;
fit?: any;
shouldRedactExplicitContent?: boolean;
shouldAnimate?: boolean;
onClose?(): void;
shouldHideMediaOptions?: boolean;
shouldAnimateCarousel?: boolean;
className?: string;
}>;
export const MediaModal = findComponentByCodeLazy(".MEDIA_MODAL_CLOSE") as MediaModal;
export const ImageModal = findComponentByCodeLazy(".MEDIA_MODAL_CLOSE", "responsive") as ImageModal;
export const ModalRoot = LazyComponent(() => Modals.ModalRoot);
export const ModalHeader = LazyComponent(() => Modals.ModalHeader);