mirror of
https://github.com/spacebarchat/client.git
synced 2024-11-25 19:52:31 +01:00
some refactoring to improve message author role color fetching
This commit is contained in:
parent
6acaaf956e
commit
edb16ad7c0
@ -50,7 +50,7 @@ function Message({ message, header }: Props) {
|
|||||||
<MessageContent>
|
<MessageContent>
|
||||||
{header && (
|
{header && (
|
||||||
<span className="message-details">
|
<span className="message-details">
|
||||||
<MessageAuthor message={message} />
|
<MessageAuthor message={message} guild={guild} />
|
||||||
<MessageDetails message={message} position="top" />
|
<MessageDetails message={message} position="top" />
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
|
@ -2,7 +2,9 @@ import { observer } from "mobx-react-lite";
|
|||||||
import React, { useContext } from "react";
|
import React, { useContext } from "react";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import { ContextMenuContext } from "../../contexts/ContextMenuContext";
|
import { ContextMenuContext } from "../../contexts/ContextMenuContext";
|
||||||
|
import useLogger from "../../hooks/useLogger";
|
||||||
import { useAppStore } from "../../stores/AppStore";
|
import { useAppStore } from "../../stores/AppStore";
|
||||||
|
import Guild from "../../stores/objects/Guild";
|
||||||
import GuildMember from "../../stores/objects/GuildMember";
|
import GuildMember from "../../stores/objects/GuildMember";
|
||||||
import { MessageLike } from "../../stores/objects/Message";
|
import { MessageLike } from "../../stores/objects/Message";
|
||||||
import Floating from "../floating/Floating";
|
import Floating from "../floating/Floating";
|
||||||
@ -21,14 +23,17 @@ const Container = styled.div`
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
message: MessageLike;
|
message: MessageLike;
|
||||||
|
guild?: Guild;
|
||||||
}
|
}
|
||||||
|
|
||||||
function MessageAuthor({ message }: Props) {
|
function MessageAuthor({ message, guild }: Props) {
|
||||||
const app = useAppStore();
|
const app = useAppStore();
|
||||||
|
const logger = useLogger("MessageAuthor");
|
||||||
const contextMenu = useContext(ContextMenuContext);
|
const contextMenu = useContext(ContextMenuContext);
|
||||||
const [color, setColor] = React.useState<string | undefined>(undefined);
|
const [color, setColor] = React.useState<string | undefined>(undefined);
|
||||||
const [eventData, setEventData] = React.useState<React.MouseEvent<HTMLDivElement, MouseEvent> | undefined>();
|
const [eventData, setEventData] = React.useState<React.MouseEvent<HTMLDivElement, MouseEvent> | undefined>();
|
||||||
const [member, setMember] = React.useState<GuildMember | undefined>(undefined);
|
const [member, setMember] = React.useState<GuildMember | undefined>(undefined);
|
||||||
|
const { members } = guild || {};
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!eventData) return;
|
if (!eventData) return;
|
||||||
@ -44,14 +49,12 @@ function MessageAuthor({ message }: Props) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if ("guild_id" in message && message.guild_id) {
|
if (!members) return;
|
||||||
const guild = app.guilds.get(message.guild_id!);
|
|
||||||
if (!guild) return;
|
const member = members.get(message.author.id);
|
||||||
const member = guild.members.get(message.author.id);
|
|
||||||
if (!member) return;
|
if (!member) return;
|
||||||
setColor(member.roleColor);
|
setColor(member.roleColor);
|
||||||
}
|
}, [message, members]);
|
||||||
}, [message]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Floating
|
<Floating
|
||||||
|
Loading…
Reference in New Issue
Block a user