refactor: profile component for better performance

This commit is contained in:
Tristan Yang
2022-09-05 22:49:03 +08:00
parent 8739cc688e
commit cb8f0c0aef
5 changed files with 38 additions and 10 deletions
+24 -1
View File
@@ -42,6 +42,30 @@ const User: FC<Props> = ({
};
if (!curr) return null;
const online = curr.online || curr.uid == loginUid;
if (!popover)
return (
<ContextMenu
cid={cid}
uid={uid}
enable={enableContextMenu}
visible={contextMenuVisible}
hide={hideContextMenu}
>
<StyledWrapper
size={avatarSize}
className={`${interactive ? "interactive" : ""} ${compact ? "compact" : ""}`}
onDoubleClick={dm ? handleDoubleClick : undefined}
onContextMenu={enableContextMenu ? handleContextMenuEvent : undefined}
>
<div className="avatar">
<Avatar url={curr.avatar} name={curr.name} alt="avatar" />
<div className={`status ${online ? "online" : "offline"}`}></div>
</div>
{!compact && <span className="name">{curr?.name}</span>}
{owner && <IconOwner />}
</StyledWrapper>
</ContextMenu>
);
return (
<ContextMenu
cid={cid}
@@ -53,7 +77,6 @@ const User: FC<Props> = ({
<Tippy
inertia={true}
interactive
disabled={!popover}
placement="left"
trigger="click"
content={<Profile uid={uid} type="card" cid={cid} />}