mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-01-10 09:56:24 +00:00
fix(betterActivities): avoid passing specific props to all activities
Now only the general props are used and the application is fetched for other activities
This commit is contained in:
parent
811397de3c
commit
32476dd1df
3 changed files with 50 additions and 14 deletions
|
@ -23,7 +23,7 @@ import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin from "@utils/types";
|
import definePlugin from "@utils/types";
|
||||||
import { findComponentByCodeLazy } from "@webpack";
|
import { findComponentByCodeLazy } from "@webpack";
|
||||||
import { PresenceStore, React, Tooltip, useEffect, useState, useStateFromStores } from "@webpack/common";
|
import { PresenceStore, React, Tooltip, useEffect, useMemo, useState, useStateFromStores } from "@webpack/common";
|
||||||
import { User } from "discord-types/general";
|
import { User } from "discord-types/general";
|
||||||
|
|
||||||
import ActivityTooltip from "./components/ActivityTooltip";
|
import ActivityTooltip from "./components/ActivityTooltip";
|
||||||
|
@ -39,6 +39,7 @@ import {
|
||||||
IconCSSProperties
|
IconCSSProperties
|
||||||
} from "./types";
|
} from "./types";
|
||||||
import {
|
import {
|
||||||
|
getActivityApplication,
|
||||||
getApplicationIcons
|
getApplicationIcons
|
||||||
} from "./utils";
|
} from "./utils";
|
||||||
|
|
||||||
|
@ -155,14 +156,31 @@ export default definePlugin({
|
||||||
|
|
||||||
if (!activities.length) return null;
|
if (!activities.length) return null;
|
||||||
|
|
||||||
|
// we use these for other activities, it would be better to somehow get the corresponding activity props
|
||||||
|
const generalProps = useMemo(() => Object.keys(props).reduce((acc, key) => {
|
||||||
|
// exclude activity specific props to prevent copying them to all activities (e.g. buttons)
|
||||||
|
if (key !== "renderActions" && key !== "application") acc[key] = props[key];
|
||||||
|
return acc;
|
||||||
|
}, {} as Omit<typeof props, "renderActions" | "application">), [props]);
|
||||||
|
|
||||||
if (settings.store.allActivitiesStyle === "carousel") {
|
if (settings.store.allActivitiesStyle === "carousel") {
|
||||||
return (
|
return (
|
||||||
<div style={{ display: "flex", flexDirection: "column" }}>
|
<div style={{ display: "flex", flexDirection: "column" }}>
|
||||||
|
{currentActivity?.id === activity?.id ? (
|
||||||
<ActivityView
|
<ActivityView
|
||||||
activity={currentActivity}
|
activity={currentActivity}
|
||||||
user={user}
|
user={user}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
|
) : (
|
||||||
|
<ActivityView
|
||||||
|
activity={currentActivity}
|
||||||
|
user={user}
|
||||||
|
// fetch optional application
|
||||||
|
application={getActivityApplication(currentActivity!)}
|
||||||
|
{...generalProps}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<div
|
<div
|
||||||
className={cl("controls")}
|
className={cl("controls")}
|
||||||
style={{
|
style={{
|
||||||
|
@ -229,12 +247,20 @@ export default definePlugin({
|
||||||
gap: "5px",
|
gap: "5px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{activities.map((activity, index) => (
|
{activities.map((activity, index) =>
|
||||||
|
index === 0 ? (
|
||||||
<ActivityView
|
<ActivityView
|
||||||
key={index}
|
key={index}
|
||||||
activity={activity}
|
activity={activity}
|
||||||
user={user}
|
user={user}
|
||||||
{...props}
|
{...props}
|
||||||
|
/>) : (
|
||||||
|
<ActivityView
|
||||||
|
key={index}
|
||||||
|
activity={activity}
|
||||||
|
user={user}
|
||||||
|
application={getActivityApplication(activity)}
|
||||||
|
{...generalProps}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -86,5 +86,6 @@ export interface ActivityViewProps {
|
||||||
activity: Activity | null;
|
activity: Activity | null;
|
||||||
user: User;
|
user: User;
|
||||||
application?: Application;
|
application?: Application;
|
||||||
|
renderActions?: () => JSX.Element;
|
||||||
type: string;
|
type: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,15 @@ const { fetchApplication }: {
|
||||||
|
|
||||||
const fetchedApplications = new Map<string, Application | null>();
|
const fetchedApplications = new Map<string, Application | null>();
|
||||||
|
|
||||||
|
export function getActivityApplication({ application_id }: Activity) {
|
||||||
|
if (!application_id) return undefined;
|
||||||
|
let application = ApplicationStore.getApplication(application_id);
|
||||||
|
if (!application && fetchedApplications.has(application_id)) {
|
||||||
|
application = fetchedApplications.get(application_id) ?? null;
|
||||||
|
}
|
||||||
|
return application ?? undefined;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: replace with "renderXboxImage"?
|
// TODO: replace with "renderXboxImage"?
|
||||||
const xboxUrl = "https://discord.com/assets/9a15d086141be29d9fcd.png";
|
const xboxUrl = "https://discord.com/assets/9a15d086141be29d9fcd.png";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue