From 2f8e2181fa3b03aa5235806492ed3d501f5d4e63 Mon Sep 17 00:00:00 2001 From: Tristan Yang Date: Thu, 9 Mar 2023 20:13:30 +0800 Subject: [PATCH] feat: not show unread count while in session --- src/routes/chat/SessionList/Session.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/routes/chat/SessionList/Session.tsx b/src/routes/chat/SessionList/Session.tsx index 8321794c..1d425f57 100644 --- a/src/routes/chat/SessionList/Session.tsx +++ b/src/routes/chat/SessionList/Session.tsx @@ -3,7 +3,7 @@ import { useState, useEffect, FC } from "react"; import clsx from "clsx"; import { useDrop } from "react-dnd"; import { NativeTypes } from "react-dnd-html5-backend"; -import { useNavigate, NavLink } from "react-router-dom"; +import { useNavigate, NavLink, useMatch } from "react-router-dom"; import ContextMenu from "./ContextMenu"; import getUnreadCount, { renderPreviewMessage } from "../utils"; import User from "../../../common/component/User"; @@ -28,6 +28,9 @@ const Session: FC = ({ setDeleteChannelId, setInviteChannelId }) => { + const navPath = type == "user" ? `/chat/dm/${id}` : `/chat/channel/${id}`; + // const { pathname } = useLocation(); + const isCurrentPath = useMatch(navPath); const navigate = useNavigate(); const { addStageFile } = useUploadFile({ context: type, id }); @@ -51,7 +54,6 @@ const Session: FC = ({ }), [type, id] ); - const { visible: contextMenuVisible, handleContextMenuEvent, hideContextMenu } = useContextMenu(); const [data, setData] = useState<{ name: string; @@ -110,7 +112,7 @@ const Session: FC = ({ clsx(`nav flex gap-2 rounded-lg p-2 w-full md:hover:bg-gray-500/20`, isActive && "shadow-[inset_0_0_0_2px_#52edff]", linkActive && "bg-gray-500/20")} - to={type == "user" ? `/chat/dm/${id}` : `/chat/channel/${id}`} + to={navPath} onContextMenu={handleContextMenuEvent} >
@@ -141,7 +143,7 @@ const Session: FC = ({
0 ? `w-36` : ``)}>{renderPreviewMessage(previewMsg)} - {unreads > 0 && ( + {unreads > 0 && !isCurrentPath && ( 99 && 'w-1.5 !h-1.5 p-0 min-w-[unset]', muted && "bg-gray-500")}> {unreads > 99 ? null : unreads}