From 168d4b4cd90c6fc33dd99dd5a2f106a7812336e5 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sun, 30 Apr 2023 02:07:57 +0200 Subject: [PATCH] PlatformIndicators: Fix layout reflows - The trilogy --- src/plugins/platformIndicators.tsx | 33 ++++++++++++++---------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/plugins/platformIndicators.tsx b/src/plugins/platformIndicators.tsx index f3de128e5..eec044721 100644 --- a/src/plugins/platformIndicators.tsx +++ b/src/plugins/platformIndicators.tsx @@ -22,18 +22,15 @@ import { addDecoration, removeDecoration } from "@api/MessageDecorations"; import { Settings } from "@api/settings"; import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; -import { classes } from "@utils/misc"; import definePlugin, { OptionType } from "@utils/types"; -import { findByCodeLazy, findByPropsLazy, findLazy, findStoreLazy } from "@webpack"; +import { findByCodeLazy, findStoreLazy } from "@webpack"; import { PresenceStore, Tooltip, UserStore } from "@webpack/common"; import { User } from "discord-types/general"; const SessionsStore = findStoreLazy("SessionsStore"); -const RoleIconClasses = findLazy(m => m.roleIcon && m.clickable && !m.alt); -const RoleIconClasses2 = findByPropsLazy("roleIcon", "alt"); function Icon(path: string, viewBox = "0 0 24 24") { - return ({ color, tooltip }: { color: string; tooltip: string; }) => ( + return ({ color, tooltip, wantMargin }: { color: string; tooltip: string; wantMargin: boolean; }) => ( {(tooltipProps: any) => ( @@ -61,16 +63,16 @@ type Platform = keyof typeof Icons; const getStatusColor = findByCodeLazy(".TWITCH", ".STREAMING", ".INVISIBLE"); -const PlatformIcon = ({ platform, status }: { platform: Platform, status: string; }) => { +const PlatformIcon = ({ platform, status, wantMargin }: { platform: Platform, status: string; wantMargin: boolean; }) => { const tooltip = platform[0].toUpperCase() + platform.slice(1); const Icon = Icons[platform] ?? Icons.desktop; - return ; + return ; }; const getStatus = (id: string): Record => PresenceStore.getState()?.clientStatuses?.[id]; -const PlatformIndicator = ({ user, inline = false, marginLeft = "4px" }: { user: User; inline?: boolean; marginLeft?: string; }) => { +const PlatformIndicator = ({ user, wantMargin = true }: { user: User; wantMargin?: boolean; }) => { if (!user || user.bot) return null; if (user.id === UserStore.getCurrentUser().id) { @@ -103,26 +105,21 @@ const PlatformIndicator = ({ user, inline = false, marginLeft = "4px" }: { user: key={platform} platform={platform as Platform} status={status} + wantMargin={wantMargin} /> )); if (!icons.length) return null; return ( - + {icons} ); }; const badge: ProfileBadge = { - component: p => , + component: p => , position: BadgePosition.START, shouldShow: userInfo => !!Object.keys(getStatus(userInfo.user.id) ?? {}).length, key: "indicator" @@ -147,7 +144,7 @@ const indicatorLocations = { description: "Inside messages", onEnable: () => addDecoration("platform-indicator", props => - + ), onDisable: () => removeDecoration("platform-indicator")