Skip to content

Commit

Permalink
feat: update types
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeIlLeone committed Oct 17, 2024
1 parent e4cf2e2 commit f10b372
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 41 deletions.
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"installdir",
"Jsonifiable",
"konami",
"leaderboard",
"lezer",
"LOCALAPPDATA",
"logname",
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/apis/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export class CommandManager {
}

/**
* Code to register an slash command
* Code to register a slash command
* @param command Slash command to be registered
* @returns A callback to unregister the slash command
*/
Expand Down
1 change: 1 addition & 0 deletions src/renderer/modules/common/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface ChannelStore {
getChannel(channelId: string): Channel | undefined;
getChannelIds(guildId?: string): string[];
getDebugInfo(): DebugInfo;
getDMChannelFromUserId(userId: string): Channel | undefined;
getDMFromUserId(userId: string): string | undefined;
getDMUserIds(): string[];
getGuildChannelsVersion(guildId: string): number;
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/modules/common/components.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { LoaderType } from "@components";
import type { ClickableCompType } from "@components/Clickable";
import type { NoticeType } from "@components/Notice";
import type { OriginalTextType } from "@components/Text";
import type { ButtonType } from "../components/ButtonItem";
import type { CheckboxType } from "../components/CheckboxItem";
Expand Down Expand Up @@ -31,6 +32,8 @@ interface DiscordComponents {
FormSwitch: SwitchItemType;
FormText: FormTextCompType;
FormTextTypes: Record<FormTextTypeKey, string>;
HelpMessage: NoticeType;
HelpMessageTypes: NoticeType["HelpMessageTypes"];
Menu: ContextMenuType["ContextMenu"];
MenuCheckboxItem: ContextMenuType["MenuCheckboxItem"];
MenuControlItem: ContextMenuType["MenuControlItem"];
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/modules/common/toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const Kind = {
FAILURE: 2,
CUSTOM: 3,
CLIP: 4,
LINK: 5,
FORWARD: 6,
BOOKMARK: 7,
CLOCK: 8,
} as const;

const Position = {
Expand Down
1 change: 1 addition & 0 deletions src/renderer/modules/common/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface UserStore {
}

export interface GuildMemberStore {
getCachedSelfMember: (guildId: string) => GuildMember | null;
getCommunicationDisabledUserMap: () => Record<string, string>;
getCommunicationDisabledVersion: () => number;
getMember: (guildId: string, userId: string) => GuildMember | null;
Expand Down
16 changes: 8 additions & 8 deletions src/renderer/modules/components/ButtonItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ interface ButtonProps extends React.ComponentPropsWithoutRef<"button"> {
submittingFinishedLabel?: string;
}

interface Path {
interface Location<S = unknown> {
pathname?: string;
search?: string;
state?: S;
hash?: string;
key?: string;
}

interface LinkProps extends Omit<React.ComponentPropsWithoutRef<"a">, "href"> {
interface LinkProps<S = unknown> extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
component?: React.ComponentType;
to: string | Location<S> | ((location: Location<S>) => string | Location<S>);
replace?: boolean;
state?: unknown;
to: string | Path;
reloadDocument?: boolean;
preventScrollReset?: boolean;
relative?: "route" | "path";
innerRef?: React.Ref<HTMLAnchorElement>;
}

interface ButtonLinkProps extends LinkProps {
interface ButtonLinkProps<S = unknown> extends LinkProps<S> {
look?: string;
color?: string;
size?: string;
Expand Down
29 changes: 11 additions & 18 deletions src/renderer/modules/components/Notice.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,29 @@
import components from "@common/components";
import type React from "react";
import { filters, waitForModule } from "../webpack";
import type { Variant } from "./Text";

const Types = {
const HelpMessageTypes = {
WARNING: 0,
INFO: 1,
ERROR: 2,
POSITIVE: 3,
} as const;

interface NoticeProps {
interface HelpMessageProps {
children: React.ReactNode;
messageType: (typeof Types)[keyof typeof Types];
messageType: (typeof HelpMessageTypes)[keyof typeof HelpMessageTypes];
textColor?: string;
textVariant?: Variant;
className?: string;
}

export type NoticeType = React.FC<NoticeProps> & {
Types: typeof Types; // for backwards compat
HelpMessageTypes: typeof Types;
default: React.FC<NoticeProps>;
export type NoticeType = React.FC<HelpMessageProps> & {
Types: typeof HelpMessageTypes; // for backwards compat
HelpMessageTypes: typeof HelpMessageTypes;
};

const NoticeComp = await waitForModule<NoticeType>(filters.bySource("WARNING=0]"));
//const Notice = NoticeComp.default as NoticeType;
// Notice component is a top-level exported function
const Notice = Object.values(NoticeComp).find((v) => typeof v === "function") as NoticeType;
// Help Message Types are a top-level exported object
Notice.HelpMessageTypes = Object.values(NoticeComp).find((v) => "INFO" in v)! as typeof Types;
Notice.Types = Notice.HelpMessageTypes;
//Notice.Types = NoticeComp.HelpMessageTypes;
//Notice.HelpMessageTypes = NoticeComp.HelpMessageTypes;
const { HelpMessage } = components;
HelpMessage.HelpMessageTypes = components.HelpMessageTypes;
HelpMessage.Types = HelpMessage.HelpMessageTypes;

export default Notice;
export default HelpMessage;
2 changes: 2 additions & 0 deletions src/renderer/modules/components/RadioItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type RadioOptionType = {
tooltipPosition?: "top" | "bottom" | "left" | "right" | "center" | "window_center";
icon?: React.ComponentType<unknown>;
collapsibleContent?: React.ReactNode;
radioItemIconClassName?: string;
radioBarClassName?: string;
};

interface RadioProps {
Expand Down
1 change: 1 addition & 0 deletions src/renderer/modules/components/SwitchItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface SwitchItemProps {
note?: string;
tooltipNote?: string;
disabled?: boolean;
disabledText?: string;
hideBorder?: boolean;
style?: React.CSSProperties;
className?: string;
Expand Down
14 changes: 4 additions & 10 deletions src/renderer/modules/components/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,7 @@ interface TooltipEnums {
Aligns: typeof Aligns;
Positions: typeof Positions;
Colors: Record<
| "PRIMARY"
| "NESTED"
| "BLACK"
| "GREY"
| "BRAND"
| "GREEN"
| "YELLOW"
| "RED"
| "CUSTOM"
| "PREMIUM",
"PRIMARY" | "NESTED" | "BLACK" | "GREY" | "BRAND" | "GREEN" | "YELLOW" | "RED" | "PREMIUM",
string
>;
}
Expand All @@ -44,6 +35,7 @@ interface BaseTooltipProps {
spacing?: number;
delay?: number;
allowOverflow?: boolean;
overflowOnly?: boolean;
disableTooltipPointerEvents?: boolean;
forceOpen?: boolean;
hideOnClick?: boolean;
Expand All @@ -53,9 +45,11 @@ interface BaseTooltipProps {
className?: string;
tooltipClassName?: string;
tooltipContentClassName?: string;
tooltipPointerClassName?: string;
style?: React.CSSProperties;
tooltipStyle?: React.CSSProperties;
onTooltipShow?: () => void;
onTooltipHide?: () => void;
onAnimationRest?: (result: unknown, spring: unknown, item?: unknown) => void;
}

Expand Down
26 changes: 22 additions & 4 deletions src/types/coremods/contextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export enum ContextMenuTypes {
Account = "account",
ActivityShelfItemContext = "activity-shelf-item-context",
AddQuestions = "add-questions",
AppDetailsMoreMenu = "app-details-more-menu",
ApplicationDirectoryProfile = "application-directory-profile",
AttachmentLinkContext = "attachment-link-context",
/** Right-click mute or deafen buttons */
Expand All @@ -36,32 +37,39 @@ export enum ContextMenuTypes {
ChannelAttach = "channel-attach",
ChannelAutocomplete = "channel-autocomplete",
ChannelCallOverflowPopout = "channel-call-overflow-popout",
ChannelNotificationCustomSettingsItems = "ChannelNotificationCustomSettingsItems",
ClipsContext = "clips-context",
ClipsMoreOptions = "clips-more-options",
CommandListSort = "command-list-sort",
/** Right-click channel */
ChannelContext = "channel-context",
/** Right-click a channel mention */
ChannelMentionContext = "channel-mention-context",
ChannelSummariesContextMenu = "channel-summaries-context-menu",
ChannelNotificationCustomSettingsItems = "ChannelNotificationCustomSettingsItems",
ClipsContext = "clips-context",
ClipsMoreOptions = "clips-more-options",
CommandListSort = "command-list-sort",
ComponentButton = "component-button",
ContentInventoryContext = "content-inventory-context",
CopyId = "copy-id",
Demo = "demo",
/** Right-click a role */
DevContext = "dev-context",
DevtoolsOverflow = "devtools-overflow",
DiscoveryEntrypointContextMenu = "discovery-entrypoint-context-menu",
EditProfilePopout = "edit-profile-popout",
ExitOptions = "exit-options",
/** Right-click an emoji or sticker in the popout */
ExpressionPicker = "expression-picker",
/** Right-click the favorites server icon */
FavoriteServerContext = "favorite-server-context",
FavoritesHeaderPopout = "favorites-header-popout",
ForumTag = "forum-tag",
/** Click the triple dots icon for a user in the home screen */
FriendRow = "friend-row",
GameContext = "game-context",
GameProfileContext = "game-profile-context",
/** Right-click a group chat */
GdmContext = "gdm-context",
GlobalDiscoverySearchFilterOptions = "global-discovery-search-filter-options",
GlobalDiscoveryTabsOverflowMenu = "global-discovery-tabs-overflow-menu",
/** Right-click "Browse Channels" */
GuildBrowseChannelsContextMenu = "guild-browse-channels-context-menu",
/** Right-click guild icon */
Expand All @@ -77,25 +85,30 @@ export enum ContextMenuTypes {
/** Right-click a role in the guild settings */
GuildSettingsRoleContext = "guild-settings-role-context",
GuildShopContext = "guild-shop-context",
ImageContextCommandPopout = "image-context-commands-popout",
ImageContext = "image-context",
JoinRequestGuildContext = "join-request-guild-context",
LaunchContext = "launch-context",
LeaderboardPopoutContextMenu = "leaderboard-popout-context-menu",
ManageBroadcast = "manage-broadcast",
ManageIntegration = "manage-integration",
ManageMultiAccount = "manage-multi-account",
ManageStreams = "manage-streams",
MemberApplicationContextMenu = "member-application-context-menu",
MemberApplicationsTabsOverflowMenu = "member-applications-tabs-overflow-menu",
MemberListSettingsMenu = "member-list-settings-menu",
MemberSafetyFlags = "member-safety-flags",
MembersTableJoinMethodMenu = "members-table-join-method-menu",
MembersTableSortMenu = "members-table-sort-menu",
MentionsFilter = "mentions-filter",
/** Click the triple dots on a message popover */
MessageActions = "message-actions",
MessageReminderCreate = "message-reminder-create",
MessageReminderSnooze = "message-reminder-snooze",
/** Right-click message */
Message = "message",
ModerationRaidContext = "moderation-raid-context",
NonUserBotProfileOverflowMenu = "non-user-bot-profile-overflow-menu",
NotificationActions = "notification-actions",
NowPlayingMenu = "now-playing-menu",
Overlay = "overlay",
Expand All @@ -110,6 +123,8 @@ export enum ContextMenuTypes {
RtcChannel = "rtc-channel",
SearchResults = "search-results",
SetImageForAction = "set-image-for-action",
SetStatusSubmenuMobileWeb = "set-status-submenu-mobile-web",
SetStatusSubmenu = "set-status-submenu",
SignupButtonContext = "signup-button-context",
SortAndView = "sort-and-view",
SoundButtonContext = "sound-button-context",
Expand All @@ -121,6 +136,7 @@ export enum ContextMenuTypes {
Status = "status",
StreamContext = "stream-context",
SubscriptionContext = "subscription-context",
SwitchAccountsSubmenu = "switch-accounts-submenu",
TestSkus = "test-skus",
TestStoreListing = "test-store-listing",
TextContext = "text-context",
Expand All @@ -129,6 +145,8 @@ export enum ContextMenuTypes {
ThreadContext = "thread-context",
TransferMenu = "transfer-menu",
UnknownUserContext = "unknown-user-context",
UserBotProfileAddApp = "user-bot-profile-add-app",
UserBotProfileOverflowMenu = "user-bot-profile-overflow-menu",
/** Right-click user */
UserContext = "user-context",
UserProfileActions = "user-profile-actions",
Expand Down

0 comments on commit f10b372

Please sign in to comment.