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

@ -8,7 +8,7 @@ import { definePluginSettings } from "@api/Settings";
import { getUserSettingLazy } from "@api/UserSettings"; import { getUserSettingLazy } from "@api/UserSettings";
import { ImageIcon } from "@components/Icons"; import { ImageIcon } from "@components/Icons";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { getCurrentGuild, openMediaModal } from "@utils/discord"; import { getCurrentGuild, openImageModal } from "@utils/discord";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy } from "@webpack"; import { findByPropsLazy } from "@webpack";
import { Clipboard, GuildStore, Menu, PermissionStore } from "@webpack/common"; import { Clipboard, GuildStore, Menu, PermissionStore } from "@webpack/common";
@ -99,7 +99,7 @@ export default definePlugin({
id="vc-view-role-icon" id="vc-view-role-icon"
label="View Role Icon" label="View Role Icon"
action={() => { action={() => {
openMediaModal(`${location.protocol}//${window.GLOBAL_ENV.CDN_HOST}/role-icons/${role.id}/${role.icon}.${settings.store.roleIconFileFormat}`); openImageModal(`${location.protocol}//${window.GLOBAL_ENV.CDN_HOST}/role-icons/${role.id}/${role.icon}.${settings.store.roleIconFileFormat}`);
}} }}
icon={ImageIcon} icon={ImageIcon}
/> />

View file

@ -19,7 +19,7 @@
import { NavContextMenuPatchCallback } from "@api/ContextMenu"; import { NavContextMenuPatchCallback } from "@api/ContextMenu";
import { ScreenshareIcon } from "@components/Icons"; import { ScreenshareIcon } from "@components/Icons";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { openMediaModal } from "@utils/discord"; import { openImageModal } from "@utils/discord";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
import { Menu } from "@webpack/common"; import { Menu } from "@webpack/common";
import { Channel, User } from "discord-types/general"; import { Channel, User } from "discord-types/general";
@ -57,7 +57,7 @@ export const handleViewPreview = async ({ guildId, channelId, ownerId }: Applica
const previewUrl = await ApplicationStreamPreviewStore.getPreviewURL(guildId, channelId, ownerId); const previewUrl = await ApplicationStreamPreviewStore.getPreviewURL(guildId, channelId, ownerId);
if (!previewUrl) return; if (!previewUrl) return;
openMediaModal(previewUrl); openImageModal(previewUrl);
}; };
export const addViewStreamContext: NavContextMenuPatchCallback = (children, { userId }: { userId: string | bigint; }) => { export const addViewStreamContext: NavContextMenuPatchCallback = (children, { userId }: { userId: string | bigint; }) => {

View file

@ -156,14 +156,14 @@ export default definePlugin({
patches: [ patches: [
{ {
find: ".contain,SCALE_DOWN:", find: "Messages.OPEN_IN_BROWSER",
replacement: { replacement: {
// there are 2 image thingies. one for carosuel and one for the single image. // there are 2 image thingies. one for carosuel and one for the single image.
// so thats why i added global flag. // so thats why i added global flag.
// also idk if this patch is good, should it be more specific? // also idk if this patch is good, should it be more specific?
// https://regex101.com/r/xfvNvV/1 // https://regex101.com/r/xfvNvV/1
match: /\.slide,\i\),/g, match: /return.{1,200}\.wrapper.{1,200}src:\i,/g,
replace: `$&id:"${ELEMENT_ID}",` replace: `$&id: '${ELEMENT_ID}',`
} }
}, },

View file

@ -7,7 +7,7 @@
import "./styles.css"; import "./styles.css";
import { classNameFactory } from "@api/Styles"; import { classNameFactory } from "@api/Styles";
import { openMediaModal, openUserProfile } from "@utils/discord"; import { openImageModal, openUserProfile } from "@utils/discord";
import { classes } from "@utils/misc"; import { classes } from "@utils/misc";
import { ModalRoot, ModalSize, openModal } from "@utils/modal"; import { ModalRoot, ModalSize, openModal } from "@utils/modal";
import { useAwaiter } from "@utils/react"; import { useAwaiter } from "@utils/react";
@ -80,7 +80,7 @@ function GuildInfoModal({ guild }: GuildProps) {
className={cl("banner")} className={cl("banner")}
src={bannerUrl} src={bannerUrl}
alt="" alt=""
onClick={() => openMediaModal(bannerUrl)} onClick={() => openImageModal(bannerUrl)}
/> />
)} )}
@ -89,7 +89,7 @@ function GuildInfoModal({ guild }: GuildProps) {
? <img ? <img
src={iconUrl} src={iconUrl}
alt="" alt=""
onClick={() => openMediaModal(iconUrl)} onClick={() => openImageModal(iconUrl)}
/> />
: <div aria-hidden className={classes(IconClasses.childWrapper, IconClasses.acronym)}>{guild.acronym}</div> : <div aria-hidden className={classes(IconClasses.childWrapper, IconClasses.acronym)}>{guild.acronym}</div>
} }
@ -151,7 +151,7 @@ function Owner(guildId: string, owner: User) {
return ( return (
<div className={cl("owner")}> <div className={cl("owner")}>
<img src={ownerAvatarUrl} alt="" onClick={() => openMediaModal(ownerAvatarUrl)} /> <img src={ownerAvatarUrl} alt="" onClick={() => openImageModal(ownerAvatarUrl)} />
{Parser.parse(`<@${owner.id}>`)} {Parser.parse(`<@${owner.id}>`)}
</div> </div>
); );

View file

@ -21,7 +21,7 @@ import "./spotifyStyles.css";
import { Flex } from "@components/Flex"; import { Flex } from "@components/Flex";
import { ImageIcon, LinkIcon, OpenExternalIcon } from "@components/Icons"; import { ImageIcon, LinkIcon, OpenExternalIcon } from "@components/Icons";
import { debounce } from "@shared/debounce"; import { debounce } from "@shared/debounce";
import { openMediaModal } from "@utils/discord"; import { openImageModal } from "@utils/discord";
import { classes, copyWithToast } from "@utils/misc"; import { classes, copyWithToast } from "@utils/misc";
import { ContextMenuApi, FluxDispatcher, Forms, Menu, React, useEffect, useState, useStateFromStores } from "@webpack/common"; import { ContextMenuApi, FluxDispatcher, Forms, Menu, React, useEffect, useState, useStateFromStores } from "@webpack/common";
@ -229,7 +229,7 @@ function AlbumContextMenu({ track }: { track: Track; }) {
id="view-cover" id="view-cover"
label="View Album Cover" label="View Album Cover"
// trolley // trolley
action={() => openMediaModal(track.album.image.url)} action={() => openImageModal(track.album.image.url)}
icon={ImageIcon} icon={ImageIcon}
/> />
<Menu.MenuControlItem <Menu.MenuControlItem

View file

@ -20,7 +20,7 @@ import { NavContextMenuPatchCallback } from "@api/ContextMenu";
import { definePluginSettings } from "@api/Settings"; import { definePluginSettings } from "@api/Settings";
import { ImageIcon } from "@components/Icons"; import { ImageIcon } from "@components/Icons";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { openMediaModal } from "@utils/discord"; import { openImageModal } from "@utils/discord";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { GuildMemberStore, IconUtils, Menu } from "@webpack/common"; import { GuildMemberStore, IconUtils, Menu } from "@webpack/common";
import type { Channel, Guild, User } from "discord-types/general"; import type { Channel, Guild, User } from "discord-types/general";
@ -78,10 +78,9 @@ function openImage(url: string) {
u.searchParams.set("size", "4096"); u.searchParams.set("size", "4096");
const originalUrl = u.toString(); const originalUrl = u.toString();
openMediaModal({ openImageModal(url, {
url,
original: originalUrl, original: originalUrl,
maxHeight: 256 height: 256
}); });
} }

View file

@ -17,10 +17,10 @@
*/ */
import { MessageObject } from "@api/MessageEvents"; 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 { 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 * Open the invite modal
@ -108,22 +108,25 @@ export function sendMessage(
return MessageActions.sendMessage(channelId, messageData, waitForChannelReady, extra); return MessageActions.sendMessage(channelId, messageData, waitForChannelReady, extra);
} }
/** export function openImageModal(url: string, props?: Partial<React.ComponentProps<ImageModal>>): string {
*
* @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";
return openModal(modalProps => ( return openModal(modalProps => (
<MediaModal <ModalRoot
{...modalProps} {...modalProps}
{...mediaModalProps} className={ModalImageClasses.modal}
shouldAnimateCarousel size={ModalSize.DYNAMIC}>
items={[media]} <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 ImageModal = ComponentType<{
export type MediaData = { className?: string;
url: string; src: string;
original?: string; placeholder: string;
type?: string; original: string;
alt?: string;
width?: number; width?: number;
height?: number; height?: number;
animated?: boolean;
responsive?: boolean;
renderLinkComponent(props: any): ReactNode;
renderForwardComponent(props: any): ReactNode;
maxWidth?: number; maxWidth?: number;
maxHeight?: number; maxHeight?: number;
} & Record<PropertyKey, any>; shouldAnimate?: boolean;
onClose?(): void;
export type MediaModal = ComponentType<{
onClose?: () => void;
items: MediaData[];
startingIndex?: number;
onIndexChange?: (...args: any[]) => void;
fit?: any;
shouldRedactExplicitContent?: boolean;
shouldHideMediaOptions?: boolean; 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 ModalRoot = LazyComponent(() => Modals.ModalRoot);
export const ModalHeader = LazyComponent(() => Modals.ModalHeader); export const ModalHeader = LazyComponent(() => Modals.ModalHeader);