From 80b986ce362adbea4bab0eb4e5f77e0697297f81 Mon Sep 17 00:00:00 2001 From: Puyodead1 Date: Thu, 11 Jan 2024 20:54:46 -0500 Subject: [PATCH] fix user context menu not showing if member fetch fails --- src/components/messaging/MessageAuthor.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/messaging/MessageAuthor.tsx b/src/components/messaging/MessageAuthor.tsx index 7c8c653..c8e1f04 100644 --- a/src/components/messaging/MessageAuthor.tsx +++ b/src/components/messaging/MessageAuthor.tsx @@ -3,6 +3,7 @@ import React, { useContext } from "react"; import styled from "styled-components"; import { ContextMenuContext } from "../../contexts/ContextMenuContext"; import { useAppStore } from "../../stores/AppStore"; +import GuildMember from "../../stores/objects/GuildMember"; import { MessageLike } from "../../stores/objects/Message"; import Floating from "../floating/Floating"; import FloatingTrigger from "../floating/FloatingTrigger"; @@ -26,11 +27,20 @@ function MessageAuthor({ message }: Props) { const app = useAppStore(); const contextMenu = useContext(ContextMenuContext); const [color, setColor] = React.useState(undefined); + const [eventData, setEventData] = React.useState | undefined>(); + const [member, setMember] = React.useState(undefined); + + React.useEffect(() => { + if (!eventData) return; + contextMenu.onContextMenu(eventData, { type: "user", user: message.author, member }); + }, [eventData, member]); const onContextMenu = async (e: React.MouseEvent) => { e.preventDefault(); - const member = await app.guilds.get(message.guild_id!)?.members.resolve(message.author.id); - contextMenu.onContextMenu(e, { type: "user", user: message.author, member }); + e.stopPropagation(); + + setEventData(e); + app.guilds.get(message.guild_id!)?.members.resolve(message.author.id).then(setMember); }; React.useEffect(() => {