refactor(memberListActivities): move types to their own file

This commit is contained in:
D3SOX 2024-04-18 08:03:08 +02:00
parent 04cf952fe3
commit c0f97446b8
No known key found for this signature in database
GPG key ID: 39EC1673FC37B048
2 changed files with 81 additions and 73 deletions

View file

@ -24,12 +24,12 @@ import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy, findComponentByCodeLazy, findStoreLazy } from "@webpack"; 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 { User } from "discord-types/general";
import type { ImgHTMLAttributes } from "react";
import { SpotifyIcon } from "./components/SpotifyIcon"; import { SpotifyIcon } from "./components/SpotifyIcon";
import { TwitchIcon } from "./components/TwitchIcon"; import { TwitchIcon } from "./components/TwitchIcon";
import { Activity, ActivityListIcon, Application, ApplicationIcon, Timestamp } from "./types";
const settings = definePluginSettings({ const settings = definePluginSettings({
iconSize: { 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-"); 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<HTMLImageElement> & {
src: string;
alt: string;
};
activity: Activity;
application?: Application;
}
interface ActivityListIcon {
iconElement: JSX.Element;
tooltip?: JSX.Element | string;
}
const ApplicationStore: { const ApplicationStore: {
getApplication: (id: string) => Application | null; getApplication: (id: string) => Application | null;
} = findStoreLazy("ApplicationStore"); } = findStoreLazy("ApplicationStore");
@ -296,7 +226,6 @@ export default definePlugin({
tooltip: <ActivityTooltip activity={spotifyActivity} /> tooltip: <ActivityTooltip activity={spotifyActivity} />
}); });
} }
const twitchActivity = activities.find(({ name }) => name === "Twitch"); const twitchActivity = activities.find(({ name }) => name === "Twitch");
if (twitchActivity) { if (twitchActivity) {
icons.push({ icons.push({
@ -304,6 +233,7 @@ export default definePlugin({
tooltip: <ActivityTooltip activity={twitchActivity} /> tooltip: <ActivityTooltip activity={twitchActivity} />
}); });
} }
const applicationIcons = getApplicationIcons(activities); const applicationIcons = getApplicationIcons(activities);
if (applicationIcons.length) { if (applicationIcons.length) {
const compareImageSource = (a: ApplicationIcon, b: ApplicationIcon) => { const compareImageSource = (a: ApplicationIcon, b: ApplicationIcon) => {

View file

@ -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<HTMLImageElement> & {
src: string;
alt: string;
};
activity: Activity;
application?: Application;
}
export interface ActivityListIcon {
iconElement: JSX.Element;
tooltip?: JSX.Element | string;
}