Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ShowConnections: Cap max number of connections displayed #3156

Open
wants to merge 19 commits into
base: dev
Choose a base branch
from
46 changes: 40 additions & 6 deletions src/plugins/showConnections/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import ErrorBoundary from "@components/ErrorBoundary";
import { Flex } from "@components/Flex";
import { CopyIcon, LinkIcon } from "@components/Icons";
import { Devs } from "@utils/constants";
import { openUserProfile } from "@utils/discord";
import { copyWithToast } from "@utils/misc";
import definePlugin, { OptionType } from "@utils/types";
import { findByCodeLazy, findByPropsLazy } from "@webpack";
import { Tooltip, UserProfileStore } from "@webpack/common";
import { Icons, Tooltip, UserProfileStore } from "@webpack/common";
import { User } from "discord-types/general";

import { VerifiedIcon } from "./VerifiedIcon";
Expand Down Expand Up @@ -57,6 +58,11 @@ const settings = definePluginSettings({
{ label: "Cozy", value: Spacing.COZY }, // US Spelling :/
{ label: "Roomy", value: Spacing.ROOMY }
]
},
maxNumberOfConnections: {
type: OptionType.NUMBER,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slider would be better. just do 5-50

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a slider doesn't work due to the fact that the size of the icons is customizable, leading to a multiple of seven -1 not always being the ideal number for an even row

description: "Max number of connections to show",
default: 13,
}
});

Expand Down Expand Up @@ -84,24 +90,52 @@ const profilePopoutComponent = ErrorBoundary.wrap(
);

function ConnectionsComponent({ id, theme }: { id: string, theme: string; }) {
const profile = UserProfileStore.getUserProfile(id);
const profile: { connectedAccounts: Connection[]; } = UserProfileStore.getUserProfile(id);
sadan4 marked this conversation as resolved.
Show resolved Hide resolved
if (!profile)
return null;

const connections: Connection[] = profile.connectedAccounts;
if (!connections?.length)
const { connectedAccounts } = profile;
if (!connectedAccounts?.length)
return null;

let connections: React.JSX.Element[];
if (connectedAccounts.length > settings.store.maxNumberOfConnections) {
connections = connectedAccounts.slice(0, settings.store.maxNumberOfConnections).map(connection => <CompactConnectionComponent connection={connection} theme={theme} key={connection.id} />);
connections.push(<ConnectionsMoreIcon onClick={() => openUserProfile(id)} />);
sadan4 marked this conversation as resolved.
Show resolved Hide resolved
sadan4 marked this conversation as resolved.
Show resolved Hide resolved
} else {
connections = connectedAccounts.map(connection => <CompactConnectionComponent connection={connection} theme={theme} key={connection.id} />);
sadan4 marked this conversation as resolved.
Show resolved Hide resolved
}
return (
<Flex style={{
gap: getSpacingPx(settings.store.iconSpacing),
flexWrap: "wrap"
}}>
{connections.map(connection => <CompactConnectionComponent connection={connection} theme={theme} key={connection.id} />)}
{connections}
</Flex>
);
}

function ConnectionsMoreIcon({ onClick }: { onClick: () => void; }) {
return (
<Tooltip
text={
<span className="vc-sc-tooltip">
<span className="vc-sc-connection-name">
View All Connections
</span>
</span>
}
>
sadan4 marked this conversation as resolved.
Show resolved Hide resolved
{props => (
<Icons.MoreHorizontalIcon
{...props}
onClick={onClick}
sadan4 marked this conversation as resolved.
Show resolved Hide resolved
className="vc-user-connection"
/>
)}
</Tooltip>
);
}

function CompactConnectionComponent({ connection, theme }: { connection: Connection, theme: string; }) {
const platform = platforms.get(useLegacyPlatformType(connection.type));
const url = platform.getPlatformUserUrl?.(connection);
Expand Down
Loading