From a015cf96f6413c718f1acfa5c4c27a2cd4b9f594 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Thu, 19 Sep 2024 05:25:31 -0300 Subject: [PATCH] UserVoiceShow: Fix setting name --- src/plugins/userVoiceShow/components.tsx | 41 +++++++++++------------- src/plugins/userVoiceShow/index.tsx | 6 ++-- src/plugins/userVoiceShow/style.css | 10 ++++-- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/plugins/userVoiceShow/components.tsx b/src/plugins/userVoiceShow/components.tsx index fd7dbd29e..095785dd0 100644 --- a/src/plugins/userVoiceShow/components.tsx +++ b/src/plugins/userVoiceShow/components.tsx @@ -8,7 +8,7 @@ import { classNameFactory } from "@api/Styles"; import ErrorBoundary from "@components/ErrorBoundary"; import { classes } from "@utils/misc"; import { findByPropsLazy, findComponentByCodeLazy, findStoreLazy } from "@webpack"; -import { ChannelStore, GuildStore, IconUtils, NavigationRouter, PermissionsBits, PermissionStore, showToast, Text, Toasts, Tooltip, useCallback, useMemo, UserStore, useStateFromStores } from "@webpack/common"; +import { ChannelStore, GuildStore, IconUtils, NavigationRouter, PermissionsBits, PermissionStore, React, showToast, Text, Toasts, Tooltip, useMemo, UserStore, useStateFromStores } from "@webpack/common"; import { Channel } from "discord-types/general"; const cl = classNameFactory("vc-uvs-"); @@ -17,7 +17,7 @@ const { selectVoiceChannel } = findByPropsLazy("selectChannel", "selectVoiceChan const VoiceStateStore = findStoreLazy("VoiceStateStore"); const UserSummaryItem = findComponentByCodeLazy("defaultRenderUser", "showDefaultAvatarsForNullUsers"); -interface IconProps extends React.HTMLAttributes { +interface IconProps extends React.ComponentPropsWithoutRef<"div"> { size?: number; } @@ -71,23 +71,18 @@ interface VoiceChannelTooltipProps { function VoiceChannelTooltip({ channel }: VoiceChannelTooltipProps) { const voiceStates = useStateFromStores([VoiceStateStore], () => VoiceStateStore.getVoiceStatesForChannel(channel.id)); + const users = useMemo( () => Object.values(voiceStates).map(voiceState => UserStore.getUser(voiceState.userId)).filter(user => user != null), [voiceStates] ); - const guild = useMemo( - () => channel.getGuildId() == null ? undefined : GuildStore.getGuild(channel.getGuildId()), - [channel] - ); - - const guildIcon = useMemo(() => { - return guild?.icon == null ? undefined : IconUtils.getGuildIconURL({ - id: guild.id, - icon: guild.icon, - size: 30 - }); - }, [guild]); + const guild = channel.getGuildId() == null ? undefined : GuildStore.getGuild(channel.getGuildId()); + const guildIcon = guild?.icon == null ? undefined : IconUtils.getGuildIconURL({ + id: guild.id, + icon: guild.icon, + size: 30 + }); return ( <> @@ -103,7 +98,7 @@ function VoiceChannelTooltip({ channel }: VoiceChannelTooltipProps) { @@ -119,11 +114,14 @@ const clickTimers = {} as Record; export const VoiceChannelIndicator = ErrorBoundary.wrap(({ userId }: VoiceChannelIndicatorProps) => { const channelId = useStateFromStores([VoiceStateStore], () => VoiceStateStore.getVoiceStateForUser(userId)?.channelId as string | undefined); - const channel = useMemo(() => channelId == null ? undefined : ChannelStore.getChannel(channelId), [channelId]); - const onClick = useCallback((e: React.MouseEvent) => { + const channel = channelId == null ? undefined : ChannelStore.getChannel(channelId); + if (channel == null) return null; + + function onClick(e: React.MouseEvent) { e.preventDefault(); e.stopPropagation(); + if (channel == null || channelId == null) return; if (!PermissionStore.can(PermissionsBits.VIEW_CHANNEL, channel)) { @@ -147,18 +145,15 @@ export const VoiceChannelIndicator = ErrorBoundary.wrap(({ userId }: VoiceChanne delete clickTimers[channelId]; }, 250); } - }, [channelId]); + } - const isLocked = useMemo(() => { - return !PermissionStore.can(PermissionsBits.VIEW_CHANNEL, channel) || !PermissionStore.can(PermissionsBits.CONNECT, channel); - }, [channelId]); - - if (channel == null) return null; + const isLocked = !PermissionStore.can(PermissionsBits.VIEW_CHANNEL, channel) || !PermissionStore.can(PermissionsBits.CONNECT, channel); return ( } tooltipClassName={cl("tooltip-container")} + tooltipContentClassName={cl("tooltip-content")} > {props => isLocked ? diff --git a/src/plugins/userVoiceShow/index.tsx b/src/plugins/userVoiceShow/index.tsx index dee713b5e..5efd936ce 100644 --- a/src/plugins/userVoiceShow/index.tsx +++ b/src/plugins/userVoiceShow/index.tsx @@ -32,7 +32,7 @@ const settings = definePluginSettings({ default: true, restartNeeded: true }, - showInVoiceMemberList: { + showInMemberList: { type: OptionType.BOOLEAN, description: "Show a user's Voice Channel indicator in the member and DMs list", default: true, @@ -82,12 +82,12 @@ export default definePlugin({ match: /\.subtext,children:.+?}\)\]}\)(?=])/, replace: "$&,$self.VoiceChannelIndicator({userId:arguments[0]?.user?.id})" }, - predicate: () => settings.store.showInVoiceMemberList + predicate: () => settings.store.showInMemberList } ], start() { - if (settings.store.showInVoiceMemberList) { + if (settings.store.showInMemberList) { addDecorator("UserVoiceShow", ({ user }) => user == null ? null : ); } }, diff --git a/src/plugins/userVoiceShow/style.css b/src/plugins/userVoiceShow/style.css index b4cc00631..3e36df217 100644 --- a/src/plugins/userVoiceShow/style.css +++ b/src/plugins/userVoiceShow/style.css @@ -15,7 +15,13 @@ } .vc-uvs-tooltip-container { - max-width: 200px; + max-width: 300px; +} + +.vc-uvs-tooltip-content { + display: flex; + flex-direction: column; + gap: 6px; } .vc-uvs-guild-name { @@ -31,7 +37,5 @@ .vc-uvs-vc-members { display: flex; - margin: 8px 0; - flex-direction: row; gap: 6px; }