Access role members even when offline (up to 100), switch from members list, context menu from server #1
1 changed files with 15 additions and 3 deletions
|
@ -8,7 +8,7 @@ import ErrorBoundary from "@components/ErrorBoundary";
|
|||
import { InfoIcon } from "@components/Icons";
|
||||
import { ModalCloseButton, ModalContent, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal";
|
||||
import { findByCodeLazy, findExportedComponentLazy } from "@webpack";
|
||||
import { Constants, GuildChannelStore, GuildMemberStore, GuildStore, Parser, RestAPI, ScrollerThin, Text, Tooltip, useEffect, UserStore, useState } from "@webpack/common";
|
||||
import { Constants, GuildChannelStore, GuildMemberStore, GuildStore, Parser, RestAPI, ScrollerThin, showToast, Text, Tooltip, useEffect, UserStore, useState } from "@webpack/common";
|
||||
import { UnicodeEmoji } from "@webpack/types";
|
||||
import type { Role } from "discord-types/general";
|
||||
|
||||
|
@ -18,7 +18,8 @@ type GetRoleIconData = (role: Role, size: number) => { customIconSrc?: string; u
|
|||
const ThreeDots = findExportedComponentLazy("Dots", "AnimatedDots");
|
||||
const getRoleIconData: GetRoleIconData = findByCodeLazy("convertSurrogateToName", "customIconSrc", "unicodeEmoji");
|
||||
|
||||
|
||||
let rolesFetched2;
|
||||
let members2;
|
||||
|
||||
function getRoleIconSrc(role: Role) {
|
||||
const icon = getRoleIconData(role, 20);
|
||||
|
@ -60,6 +61,7 @@ function MembersContainer({ guildId, roleId }: { guildId: string; roleId: string
|
|||
({ body: usersInRole } = response);
|
||||
await GuildUtils.requestMembersById(guildId, usersInRole, !1);
|
||||
setRolesFetched([...rolesFetched, roleId]);
|
||||
rolesFetched2 = rolesFetched;
|
||||
clearInterval(interval);
|
||||
} catch (error) { console.error("Error fetching members:", error); }
|
||||
}, 1200);
|
||||
|
@ -144,6 +146,12 @@ function InRoleModal({ guildId, props, roleId }: { guildId: string; props: Modal
|
|||
|
||||
const [selectedRole, selectRole] = useState(roles.find(x => x.id === roleId) || roles[0]);
|
||||
|
||||
let cooldown;
|
||||
useEffect(() => {
|
||||
const timeout = setTimeout(() => cooldown = false, 1000);
|
||||
return () => clearTimeout(timeout);
|
||||
}, [selectedRole]);
|
||||
|
||||
return (
|
||||
<ErrorBoundary>
|
||||
<ModalRoot {...props} size={ModalSize.LARGE}>
|
||||
|
@ -163,7 +171,11 @@ function InRoleModal({ guildId, props, roleId }: { guildId: string; props: Modal
|
|||
return (
|
||||
<div
|
||||
className={cl("modal-list-item-btn")}
|
||||
onClick={() => selectRole(roles[index])}
|
||||
onClick={() => {
|
||||
if (selectedRole.id === roles[index].id) return;
|
||||
cooldown && !rolesFetched2.includes(roles[index].id) ? showToast("To limit ratelimiting, please wait at least a second before switching roles.")
|
||||
: (selectRole(roles[index]), cooldown = true);
|
||||
}}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
key={role.id}
|
||||
|
|
Loading…
Reference in a new issue