Compare commits

..

2 commits

Author SHA1 Message Date
sadan4
5b2a98ce0e
Merge e392958736 into 00c9aa96aa 2024-09-19 09:44:31 +01:00
Nuckyz
00c9aa96aa
UserVoiceShow: Fix setting name 2024-09-19 05:25:31 -03:00
2 changed files with 26 additions and 25 deletions

View file

@ -8,7 +8,7 @@ import { classNameFactory } from "@api/Styles";
import ErrorBoundary from "@components/ErrorBoundary"; import ErrorBoundary from "@components/ErrorBoundary";
import { classes } from "@utils/misc"; import { classes } from "@utils/misc";
import { findByPropsLazy, findComponentByCodeLazy, findStoreLazy } from "@webpack"; import { findByPropsLazy, findComponentByCodeLazy, findStoreLazy } from "@webpack";
import { ChannelStore, GuildStore, IconUtils, NavigationRouter, PermissionsBits, PermissionStore, React, showToast, Text, Toasts, Tooltip, useMemo, UserStore, useStateFromStores } from "@webpack/common"; import { ChannelStore, GuildStore, IconUtils, NavigationRouter, PermissionsBits, PermissionStore, showToast, Text, Toasts, Tooltip, useCallback, useMemo, UserStore, useStateFromStores } from "@webpack/common";
import { Channel } from "discord-types/general"; import { Channel } from "discord-types/general";
const cl = classNameFactory("vc-uvs-"); const cl = classNameFactory("vc-uvs-");
@ -17,7 +17,7 @@ const { selectVoiceChannel } = findByPropsLazy("selectChannel", "selectVoiceChan
const VoiceStateStore = findStoreLazy("VoiceStateStore"); const VoiceStateStore = findStoreLazy("VoiceStateStore");
const UserSummaryItem = findComponentByCodeLazy("defaultRenderUser", "showDefaultAvatarsForNullUsers"); const UserSummaryItem = findComponentByCodeLazy("defaultRenderUser", "showDefaultAvatarsForNullUsers");
interface IconProps extends React.ComponentPropsWithoutRef<"div"> { interface IconProps extends React.HTMLAttributes<HTMLDivElement> {
size?: number; size?: number;
} }
@ -71,18 +71,23 @@ interface VoiceChannelTooltipProps {
function VoiceChannelTooltip({ channel }: VoiceChannelTooltipProps) { function VoiceChannelTooltip({ channel }: VoiceChannelTooltipProps) {
const voiceStates = useStateFromStores([VoiceStateStore], () => VoiceStateStore.getVoiceStatesForChannel(channel.id)); const voiceStates = useStateFromStores([VoiceStateStore], () => VoiceStateStore.getVoiceStatesForChannel(channel.id));
const users = useMemo( const users = useMemo(
() => Object.values<any>(voiceStates).map(voiceState => UserStore.getUser(voiceState.userId)).filter(user => user != null), () => Object.values<any>(voiceStates).map(voiceState => UserStore.getUser(voiceState.userId)).filter(user => user != null),
[voiceStates] [voiceStates]
); );
const guild = channel.getGuildId() == null ? undefined : GuildStore.getGuild(channel.getGuildId()); const guild = useMemo(
const guildIcon = guild?.icon == null ? undefined : IconUtils.getGuildIconURL({ () => channel.getGuildId() == null ? undefined : GuildStore.getGuild(channel.getGuildId()),
id: guild.id, [channel]
icon: guild.icon, );
size: 30
}); const guildIcon = useMemo(() => {
return guild?.icon == null ? undefined : IconUtils.getGuildIconURL({
id: guild.id,
icon: guild.icon,
size: 30
});
}, [guild]);
return ( return (
<> <>
@ -98,7 +103,7 @@ function VoiceChannelTooltip({ channel }: VoiceChannelTooltipProps) {
<UserSummaryItem <UserSummaryItem
users={users} users={users}
renderIcon={false} renderIcon={false}
max={13} max={7}
size={18} size={18}
/> />
</div> </div>
@ -114,14 +119,11 @@ const clickTimers = {} as Record<string, any>;
export const VoiceChannelIndicator = ErrorBoundary.wrap(({ userId }: VoiceChannelIndicatorProps) => { export const VoiceChannelIndicator = ErrorBoundary.wrap(({ userId }: VoiceChannelIndicatorProps) => {
const channelId = useStateFromStores([VoiceStateStore], () => VoiceStateStore.getVoiceStateForUser(userId)?.channelId as string | undefined); const channelId = useStateFromStores([VoiceStateStore], () => VoiceStateStore.getVoiceStateForUser(userId)?.channelId as string | undefined);
const channel = useMemo(() => channelId == null ? undefined : ChannelStore.getChannel(channelId), [channelId]);
const channel = channelId == null ? undefined : ChannelStore.getChannel(channelId); const onClick = useCallback((e: React.MouseEvent) => {
if (channel == null) return null;
function onClick(e: React.MouseEvent) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
if (channel == null || channelId == null) return; if (channel == null || channelId == null) return;
if (!PermissionStore.can(PermissionsBits.VIEW_CHANNEL, channel)) { if (!PermissionStore.can(PermissionsBits.VIEW_CHANNEL, channel)) {
@ -145,15 +147,18 @@ export const VoiceChannelIndicator = ErrorBoundary.wrap(({ userId }: VoiceChanne
delete clickTimers[channelId]; delete clickTimers[channelId];
}, 250); }, 250);
} }
} }, [channelId]);
const isLocked = !PermissionStore.can(PermissionsBits.VIEW_CHANNEL, channel) || !PermissionStore.can(PermissionsBits.CONNECT, channel); const isLocked = useMemo(() => {
return !PermissionStore.can(PermissionsBits.VIEW_CHANNEL, channel) || !PermissionStore.can(PermissionsBits.CONNECT, channel);
}, [channelId]);
if (channel == null) return null;
return ( return (
<Tooltip <Tooltip
text={<VoiceChannelTooltip channel={channel} />} text={<VoiceChannelTooltip channel={channel} />}
tooltipClassName={cl("tooltip-container")} tooltipClassName={cl("tooltip-container")}
tooltipContentClassName={cl("tooltip-content")}
> >
{props => {props =>
isLocked ? isLocked ?

View file

@ -15,13 +15,7 @@
} }
.vc-uvs-tooltip-container { .vc-uvs-tooltip-container {
max-width: 300px; max-width: 200px;
}
.vc-uvs-tooltip-content {
display: flex;
flex-direction: column;
gap: 6px;
} }
.vc-uvs-guild-name { .vc-uvs-guild-name {
@ -37,5 +31,7 @@
.vc-uvs-vc-members { .vc-uvs-vc-members {
display: flex; display: flex;
margin: 8px 0;
flex-direction: row;
gap: 6px; gap: 6px;
} }