From ea74c1609a540a95270627c5c04f82f48ff8e980 Mon Sep 17 00:00:00 2001 From: Puyodead1 Date: Sun, 24 Dec 2023 12:40:18 -0500 Subject: [PATCH] open user popout on mention click --- src/components/floating/FloatingTrigger.tsx | 4 +- src/components/markdown/Mention.tsx | 65 ++++++++------------- 2 files changed, 27 insertions(+), 42 deletions(-) diff --git a/src/components/floating/FloatingTrigger.tsx b/src/components/floating/FloatingTrigger.tsx index 53eb010..88c728c 100644 --- a/src/components/floating/FloatingTrigger.tsx +++ b/src/components/floating/FloatingTrigger.tsx @@ -28,9 +28,9 @@ export default React.forwardRef & Popo } return ( -
+ {children} -
+ ); }, ); diff --git a/src/components/markdown/Mention.tsx b/src/components/markdown/Mention.tsx index 903702d..e09ec65 100644 --- a/src/components/markdown/Mention.tsx +++ b/src/components/markdown/Mention.tsx @@ -6,8 +6,10 @@ import Channel from "../../stores/objects/Channel"; import Role from "../../stores/objects/Role"; import User from "../../stores/objects/User"; import { hexToRGB, rgbToHsl } from "../../utils/Utils"; +import Floating from "../floating/Floating"; +import FloatingTrigger from "../floating/FloatingTrigger"; -const Container = styled.span<{ color?: string; withHover?: boolean }>` +const MentionText = styled.span<{ color?: string; withHover?: boolean }>` padding: 0 2px; border-radius: 4px; background-color: hsl(${(props) => props.color ?? "var(--primary-hsl)"} / 0.3); @@ -28,12 +30,6 @@ interface MentionProps { function UserMention({ id }: MentionProps) { const app = useAppStore(); const [user, setUser] = React.useState(null); - const ref = React.useRef(null); - - const click = (e: React.MouseEvent) => { - e.preventDefault(); - e.stopPropagation(); - }; React.useEffect(() => { const getUser = async () => { @@ -47,17 +43,20 @@ function UserMention({ id }: MentionProps) { console.log(user); - if (!user) - return ( - - @{id} - - ); + if (!user) return @{id}; return ( - - @{user.username} - + + + @{user.username} + + ); } @@ -66,7 +65,7 @@ function ChannelMention({ id }: MentionProps) { const [channel, setChannel] = React.useState(null); const navigate = useNavigate(); - const click = () => { + const onClick = () => { if (!channel) return; if (!channel.isGuildTextChannel) return; navigate(`/channels/${channel.guildId}/${channel.id}`); @@ -77,17 +76,12 @@ function ChannelMention({ id }: MentionProps) { if (channel) setChannel(channel); }, [id]); - if (!channel) - return ( - - #{id} - - ); + if (!channel) return #{id}; return ( - - #{channel.name} - + + #{channel.name} + ); } @@ -110,26 +104,17 @@ function RoleMention({ id }: MentionProps) { setColor(rgbToHsl(rgb.r, rgb.g, rgb.b)); }, [role]); - if (!role) - return ( - - @unknown-role - - ); + if (!role) return @unknown-role; return ( - - @{role.name} - + + @{role.name} + ); } function CustomMention({ id }: MentionProps) { - return ( - - {id} - - ); + return {id}; } interface Props {