From c0f97446b8e0c0a4b635e865e111d616f3ba6870 Mon Sep 17 00:00:00 2001 From: D3SOX Date: Thu, 18 Apr 2024 08:03:08 +0200 Subject: [PATCH] refactor(memberListActivities): move types to their own file --- src/plugins/memberListActivities/index.tsx | 76 +-------------------- src/plugins/memberListActivities/types.ts | 78 ++++++++++++++++++++++ 2 files changed, 81 insertions(+), 73 deletions(-) create mode 100644 src/plugins/memberListActivities/types.ts diff --git a/src/plugins/memberListActivities/index.tsx b/src/plugins/memberListActivities/index.tsx index 5cfb8d302..1c71be6ff 100644 --- a/src/plugins/memberListActivities/index.tsx +++ b/src/plugins/memberListActivities/index.tsx @@ -24,12 +24,12 @@ import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; import { findByPropsLazy, findComponentByCodeLazy, findStoreLazy } from "@webpack"; -import { Tooltip, useMemo } from "@webpack/common"; +import { React, Tooltip, useMemo } from "@webpack/common"; import { User } from "discord-types/general"; -import type { ImgHTMLAttributes } from "react"; import { SpotifyIcon } from "./components/SpotifyIcon"; import { TwitchIcon } from "./components/TwitchIcon"; +import { Activity, ActivityListIcon, Application, ApplicationIcon, Timestamp } from "./types"; const settings = definePluginSettings({ iconSize: { @@ -47,78 +47,8 @@ const settings = definePluginSettings({ }, }); -interface Timestamp { - start?: number; - end?: number; -} - -interface Activity { - created_at: number; - id: string; - name: string; - type: number; - emoji?: { - animated: boolean; - id: string; - name: string; - } - state?: string; - flags?: number; - sync_id?: string; - details?: string; - application_id?: string; - assets?: { - large_text?: string; - large_image?: string; - small_text?: string; - small_image?: string; - }; - timestamps?: Timestamp; - platform?: string; -} - const cl = classNameFactory("vc-mla-"); -interface Application { - id: string; - name: string; - icon: string; - description: string; - summary: string; - type: number; - hook: boolean; - guild_id: string; - executables: Executable[]; - verify_key: string; - publishers: Developer[]; - developers: Developer[]; - flags: number; -} - -interface Developer { - id: string; - name: string; -} - -interface Executable { - os: string; - name: string; - is_launcher: boolean; -} -interface ApplicationIcon { - image: ImgHTMLAttributes & { - src: string; - alt: string; - }; - activity: Activity; - application?: Application; -} - -interface ActivityListIcon { - iconElement: JSX.Element; - tooltip?: JSX.Element | string; -} - const ApplicationStore: { getApplication: (id: string) => Application | null; } = findStoreLazy("ApplicationStore"); @@ -296,7 +226,6 @@ export default definePlugin({ tooltip: }); } - const twitchActivity = activities.find(({ name }) => name === "Twitch"); if (twitchActivity) { icons.push({ @@ -304,6 +233,7 @@ export default definePlugin({ tooltip: }); } + const applicationIcons = getApplicationIcons(activities); if (applicationIcons.length) { const compareImageSource = (a: ApplicationIcon, b: ApplicationIcon) => { diff --git a/src/plugins/memberListActivities/types.ts b/src/plugins/memberListActivities/types.ts new file mode 100644 index 000000000..7f3f2b509 --- /dev/null +++ b/src/plugins/memberListActivities/types.ts @@ -0,0 +1,78 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import type { ImgHTMLAttributes } from "react"; + +export interface Timestamp { + start?: number; + end?: number; +} + +export interface Activity { + created_at: number; + id: string; + name: string; + type: number; + emoji?: { + animated: boolean; + id: string; + name: string; + } + state?: string; + flags?: number; + sync_id?: string; + details?: string; + application_id?: string; + assets?: { + large_text?: string; + large_image?: string; + small_text?: string; + small_image?: string; + }; + timestamps?: Timestamp; + platform?: string; +} + +export interface Application { + id: string; + name: string; + icon: string; + description: string; + summary: string; + type: number; + hook: boolean; + guild_id: string; + executables: Executable[]; + verify_key: string; + publishers: Developer[]; + developers: Developer[]; + flags: number; +} + +export interface Developer { + id: string; + name: string; +} + +export interface Executable { + os: string; + name: string; + is_launcher: boolean; +} + +export interface ApplicationIcon { + image: ImgHTMLAttributes & { + src: string; + alt: string; + }; + activity: Activity; + application?: Application; +} + +export interface ActivityListIcon { + iconElement: JSX.Element; + tooltip?: JSX.Element | string; +}