From 1781f154e10ef276241977d5df73cc87c26108d4 Mon Sep 17 00:00:00 2001 From: one Date: Thu, 29 May 2025 09:44:55 +0800 Subject: [PATCH] refactor: chat navigation triggering (#6576) * refactor(ChatNavigation): move down the navigation bar * refactor: attach listeners to MessagesContainer for better triggering experience * refactor: add delay to Tooltips * refactor: exclude some toolbars areas from triggering --- src/renderer/src/pages/home/Chat.tsx | 2 +- .../pages/home/Messages/ChatNavigation.tsx | 37 ++++++++++++++----- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/renderer/src/pages/home/Chat.tsx b/src/renderer/src/pages/home/Chat.tsx index c2ee47d43c..dbb10eb1e6 100644 --- a/src/renderer/src/pages/home/Chat.tsx +++ b/src/renderer/src/pages/home/Chat.tsx @@ -115,7 +115,7 @@ const Chat: FC = (props) => { includeUser={filterIncludeUser} onIncludeUserChange={userOutlinedItemClickHandler} /> - + = ({ containerId }) => { // Set up scroll event listener and mouse position tracking useEffect(() => { const container = document.getElementById(containerId) + const messagesContainer = container?.closest('.messages-container') as HTMLElement + if (!container) return // Handle scroll events on the container @@ -266,10 +271,14 @@ const ChatNavigation: FC = ({ containerId }) => { } const rightPosition = window.innerWidth - rightOffset - triggerWidth - const topPosition = window.innerHeight * 0.3 // 30% from top + const topPosition = window.innerHeight * 0.35 // 35% from top const height = window.innerHeight * 0.3 // 30% of window height + const target = e.target as HTMLElement + const isInExcludedArea = EXCLUDED_SELECTORS.some((selector) => target.closest(selector)) + const isInTriggerArea = + !isInExcludedArea && e.clientX > rightPosition && e.clientX < rightPosition + triggerWidth && e.clientY > topPosition && @@ -287,11 +296,21 @@ const ChatNavigation: FC = ({ containerId }) => { // Use passive: true for better scroll performance container.addEventListener('scroll', handleScroll, { passive: true }) - window.addEventListener('mousemove', handleMouseMove) + + if (messagesContainer) { + // Listen to the messages container (but with global coordinates) + messagesContainer.addEventListener('mousemove', handleMouseMove) + } else { + window.addEventListener('mousemove', handleMouseMove) + } return () => { container.removeEventListener('scroll', handleScroll) - window.removeEventListener('mousemove', handleMouseMove) + if (messagesContainer) { + messagesContainer.removeEventListener('mousemove', handleMouseMove) + } else { + window.removeEventListener('mousemove', handleMouseMove) + } if (hideTimer) { clearTimeout(hideTimer) } @@ -311,7 +330,7 @@ const ChatNavigation: FC = ({ containerId }) => { <> - + } @@ -320,7 +339,7 @@ const ChatNavigation: FC = ({ containerId }) => { /> - + } @@ -329,7 +348,7 @@ const ChatNavigation: FC = ({ containerId }) => { /> - + } @@ -338,7 +357,7 @@ const ChatNavigation: FC = ({ containerId }) => { /> - + } @@ -347,7 +366,7 @@ const ChatNavigation: FC = ({ containerId }) => { /> - + } @@ -356,7 +375,7 @@ const ChatNavigation: FC = ({ containerId }) => { /> - + }