1
0
mirror of https://github.com/spacebarchat/client.git synced 2024-11-24 03:12:29 +01:00

fix user context menu not showing if member fetch fails

This commit is contained in:
Puyodead1 2024-01-11 20:54:46 -05:00
parent a39a55fb80
commit 80b986ce36
No known key found for this signature in database
GPG Key ID: BA5F91AAEF68E5CE

View File

@ -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<string | undefined>(undefined);
const [eventData, setEventData] = React.useState<React.MouseEvent<HTMLDivElement, MouseEvent> | undefined>();
const [member, setMember] = React.useState<GuildMember | undefined>(undefined);
React.useEffect(() => {
if (!eventData) return;
contextMenu.onContextMenu(eventData, { type: "user", user: message.author, member });
}, [eventData, member]);
const onContextMenu = async (e: React.MouseEvent<HTMLDivElement, 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(() => {