From 46429fe6c1e115f878e33f3f3617a830b331eee5 Mon Sep 17 00:00:00 2001 From: Tristan Yang Date: Fri, 2 Sep 2022 21:28:00 +0800 Subject: [PATCH] fix: login user online status --- src/common/component/User/index.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/common/component/User/index.tsx b/src/common/component/User/index.tsx index 63a4b7ef..e7b4a45e 100644 --- a/src/common/component/User/index.tsx +++ b/src/common/component/User/index.tsx @@ -1,4 +1,4 @@ -import { FC } from "react"; +import { FC, memo } from "react"; import { useNavigate } from "react-router-dom"; import Tippy from "@tippyjs/react"; import IconOwner from "../../../assets/icons/owner.svg"; @@ -34,11 +34,14 @@ const User: FC = ({ }) => { const navigate = useNavigate(); const { visible: contextMenuVisible, handleContextMenuEvent, hideContextMenu } = useContextMenu(); - const curr = useAppSelector((store) => store.users.byId[uid]); + const { curr, loginUid } = useAppSelector((store) => { + return { curr: store.users.byId[uid], loginUid: store.authData.user?.uid }; + }); const handleDoubleClick = () => { navigate(`/chat/dm/${uid}`); }; if (!curr) return null; + const online = curr.online || curr.uid == loginUid; return ( = ({ >
-
+
{!compact && {curr?.name}} {owner && } @@ -73,4 +76,4 @@ const User: FC = ({ ); }; -export default User; +export default memo(User, (prev, next) => prev.uid == next.uid);