From 56e110a1a654caa3c9d0ae13eb8be8521dec779e Mon Sep 17 00:00:00 2001 From: Federico <38290480+FedeIlLeone@users.noreply.github.com> Date: Thu, 26 Oct 2023 22:56:19 +0200 Subject: [PATCH] feat(components): moved all to use common components --- src/renderer/modules/common/components.ts | 32 +++++++++++-------- .../modules/components/ButtonItem.tsx | 2 +- src/renderer/modules/components/Clickable.tsx | 8 ++--- src/renderer/modules/components/Flex.tsx | 4 ++- src/renderer/modules/components/FormItem.tsx | 2 +- src/renderer/modules/components/Loader.tsx | 8 ++--- src/renderer/modules/components/Notice.tsx | 4 +-- .../modules/components/SliderItem.tsx | 2 +- src/renderer/modules/components/Text.tsx | 10 +++--- 9 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/renderer/modules/common/components.ts b/src/renderer/modules/common/components.ts index 6e4be8788..4ae0e3955 100644 --- a/src/renderer/modules/common/components.ts +++ b/src/renderer/modules/common/components.ts @@ -1,10 +1,13 @@ -import { waitForProps } from "../webpack"; +import type { LoaderType } from "@components"; +import type { ClickableCompType } from "@components/Clickable"; +import type { OriginalTextType } from "@components/Text"; import type { ButtonType } from "../components/ButtonItem"; -import type { FormTextCompType, FormTextTypeKey } from "../components/FormText"; -import type { FormNoticeType } from "../components/FormNotice"; -import type { FormItemCompType } from "../components/FormItem"; +import type { CheckboxType } from "../components/CheckboxItem"; +import type { ContextMenuType } from "../components/ContextMenu"; import type { DividerType } from "../components/Divider"; -import type { CheckboxItemType } from "../components/CheckboxItem"; +import type { FormItemCompType } from "../components/FormItem"; +import type { FormNoticeType } from "../components/FormNotice"; +import type { FormTextCompType, FormTextTypeKey } from "../components/FormText"; import type { ModalType } from "../components/Modal"; import type { RadioType } from "../components/RadioItem"; import type { SelectCompType } from "../components/SelectItem"; @@ -13,34 +16,37 @@ import type { SwitchItemType, SwitchType } from "../components/SwitchItem"; import type { TextAreaType } from "../components/TextArea"; import type { TextInputType } from "../components/TextInput"; import type { OriginalTooltipType } from "../components/Tooltip"; -import type { ContextMenuType } from "../components/ContextMenu"; +import { waitForProps } from "../webpack"; // Expand this as needed interface DiscordComponents { Button: ButtonType; - Checkbox: CheckboxItemType; - FormDivider: DividerType + Checkbox: CheckboxType; + Clickable: ClickableCompType; + FormDivider: DividerType; FormItem: FormItemCompType; FormNotice: FormNoticeType; FormSwitch: SwitchItemType; FormText: FormTextCompType; FormTextTypes: Record; Menu: ContextMenuType["ContextMenu"]; - MenuSeparator: ContextMenuType["MenuSeparator"]; MenuCheckboxItem: ContextMenuType["MenuCheckboxItem"]; - MenuRadioItem: ContextMenuType["MenuRadioItem"]; MenuControlItem: ContextMenuType["MenuControlItem"]; MenuGroup: ContextMenuType["MenuGroup"]; MenuItem: ContextMenuType["MenuItem"]; - ModalRoot: ModalType["ModalRoot"]; + MenuRadioItem: ContextMenuType["MenuRadioItem"]; + MenuSeparator: ContextMenuType["MenuSeparator"]; + ModalCloseButton: ModalType["ModalCloseButton"]; ModalContent: ModalType["ModalContent"]; - ModalHeader: ModalType["ModalHeader"]; ModalFooter: ModalType["ModalFooter"]; - ModalCloseButton: ModalType["ModalCloseButton"]; + ModalHeader: ModalType["ModalHeader"]; + ModalRoot: ModalType["ModalRoot"]; RadioGroup: RadioType; Select: SelectCompType; Slider: SliderCompType; + Spinner: LoaderType; Switch: SwitchType; + Text: OriginalTextType; TextArea: TextAreaType; TextInput: TextInputType; Tooltip: OriginalTooltipType; diff --git a/src/renderer/modules/components/ButtonItem.tsx b/src/renderer/modules/components/ButtonItem.tsx index 0843b2abd..a0984deb1 100644 --- a/src/renderer/modules/components/ButtonItem.tsx +++ b/src/renderer/modules/components/ButtonItem.tsx @@ -1,7 +1,7 @@ import type React from "react"; import { Divider, Flex, FormText, Tooltip } from "."; -import { waitForProps } from "../webpack"; import components from "../common/components"; +import { waitForProps } from "../webpack"; interface ButtonProps extends React.ComponentPropsWithoutRef<"button"> { look?: string; diff --git a/src/renderer/modules/components/Clickable.tsx b/src/renderer/modules/components/Clickable.tsx index 497ab670c..f840448ec 100644 --- a/src/renderer/modules/components/Clickable.tsx +++ b/src/renderer/modules/components/Clickable.tsx @@ -1,5 +1,5 @@ import type React from "react"; -import { filters, waitForModule } from "../webpack"; +import components from "../common/components"; // TODO: generic type for tags? type ClickableProps = React.ComponentPropsWithoutRef<"div"> & { @@ -7,13 +7,11 @@ type ClickableProps = React.ComponentPropsWithoutRef<"div"> & { ignoreKeyPress?: boolean; }; -type ClickableCompType = React.ComponentClass> & { +export type ClickableCompType = React.ComponentClass> & { defaultProps: ClickableProps; }; -const Clickable = await waitForModule>( - filters.bySource("renderNonInteractive"), -).then((mod) => Object.values(mod).find((x) => x.prototype?.renderNonInteractive)!); +const { Clickable } = components; export type ClickableType = React.FC>; diff --git a/src/renderer/modules/components/Flex.tsx b/src/renderer/modules/components/Flex.tsx index 5f58f0097..a7d54b6ac 100644 --- a/src/renderer/modules/components/Flex.tsx +++ b/src/renderer/modules/components/Flex.tsx @@ -29,4 +29,6 @@ export type FlexType = React.FC> & { }; }; -export default await waitForModule(filters.bySource(/HORIZONTAL_REVERSE:\w+?\.horizontalReverse./)); +export default await waitForModule( + filters.bySource(/HORIZONTAL_REVERSE:\w+?\.horizontalReverse./), +); diff --git a/src/renderer/modules/components/FormItem.tsx b/src/renderer/modules/components/FormItem.tsx index 943eb314e..fa1604d10 100644 --- a/src/renderer/modules/components/FormItem.tsx +++ b/src/renderer/modules/components/FormItem.tsx @@ -1,7 +1,7 @@ import type React from "react"; import { Divider, FormText } from "."; -import { waitForProps } from "../webpack"; import components from "../common/components"; +import { waitForProps } from "../webpack"; interface FormItemCompProps extends Omit, "title"> { children: React.ReactNode; diff --git a/src/renderer/modules/components/Loader.tsx b/src/renderer/modules/components/Loader.tsx index 64cd51d65..5c08275cf 100644 --- a/src/renderer/modules/components/Loader.tsx +++ b/src/renderer/modules/components/Loader.tsx @@ -1,5 +1,5 @@ import type React from "react"; -import { filters, waitForModule } from "../webpack"; +import components from "../common/components"; const Types = { WANDERING_CUBES: "wanderingCubes", @@ -28,8 +28,4 @@ export type LoaderType = React.FC & { Type: typeof Types; }; -const Loader = await waitForModule>( - filters.bySource('"wanderingCubes"'), -).then((mod) => Object.values(mod).find((x) => typeof x === "function")!); - -export default Loader; +export default components.Spinner; diff --git a/src/renderer/modules/components/Notice.tsx b/src/renderer/modules/components/Notice.tsx index c46948b1a..693eeb8b8 100644 --- a/src/renderer/modules/components/Notice.tsx +++ b/src/renderer/modules/components/Notice.tsx @@ -22,9 +22,7 @@ export type NoticeType = React.FC & { HelpMessageTypes: typeof Types; }; -const Notice = await waitForModule( - filters.bySource("WARNING=0]"), -); +const Notice = await waitForModule(filters.bySource("WARNING=0]")); Notice.Types = Types; export default Notice; diff --git a/src/renderer/modules/components/SliderItem.tsx b/src/renderer/modules/components/SliderItem.tsx index 49f55f613..cc5a8cdaa 100644 --- a/src/renderer/modules/components/SliderItem.tsx +++ b/src/renderer/modules/components/SliderItem.tsx @@ -1,7 +1,7 @@ import type React from "react"; import { FormItem } from "."; -import { waitForProps } from "../webpack"; import components from "../common/components"; +import { waitForProps } from "../webpack"; const MarkerPositions = { ABOVE: 0, diff --git a/src/renderer/modules/components/Text.tsx b/src/renderer/modules/components/Text.tsx index be89ddb98..c9f37167c 100644 --- a/src/renderer/modules/components/Text.tsx +++ b/src/renderer/modules/components/Text.tsx @@ -1,7 +1,6 @@ import { parser } from "@common"; import type React from "react"; -import type { ObjectExports } from "../../../types"; -import { filters, getFunctionBySource, waitForModule } from "../webpack"; +import components from "../common/components"; export type Variant = | "heading-sm/normal" @@ -81,13 +80,12 @@ interface CustomTextProps extends TextProps { allowMarkdownList?: boolean; } -type OriginalTextType = React.FC; +export type OriginalTextType = React.FC; export type TextType = OriginalTextType & Record<"Normal" | "H1" | "H2" | "H3" | "H4" | "Eyebrow", OriginalTextType>; -const mod = await waitForModule(filters.bySource("data-text-variant")); -const OriginalText = getFunctionBySource(mod, "data-text-variant")!; +const TextComp = components.Text; function TextWithDefaultProps(defaultProps: CustomTextProps) { return (props: CustomTextProps) => { @@ -105,7 +103,7 @@ function TextWithDefaultProps(defaultProps: CustomTextProps) { delete props.allowMarkdownLinks; delete props.allowMarkdownHeading; delete props.allowMarkdownList; - return {newChildren}; + return {newChildren}; }; }