From 4ba836e3fa3a9928e1646b8a2c622783e83db008 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Sun, 18 Jun 2023 12:03:08 +0200 Subject: [PATCH] Left Column: Fix archive closing before forum panel (#3320) --- src/components/left/LeftColumn.tsx | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/components/left/LeftColumn.tsx b/src/components/left/LeftColumn.tsx index af76f3e56..3efdd9255 100644 --- a/src/components/left/LeftColumn.tsx +++ b/src/components/left/LeftColumn.tsx @@ -347,9 +347,23 @@ function LeftColumn({ }); useEffect( - () => (content !== LeftColumnContent.ChatList || (isFirstChatFolderActive && !isChatOpen && !isForumPanelOpen) - ? captureEscKeyListener(() => handleReset()) - : undefined), + () => { + const isArchived = content === LeftColumnContent.Archived; + const isChatList = content === LeftColumnContent.ChatList; + const noChatOrForumOpen = !isChatOpen && !isForumPanelOpen; + // We listen for escape key only in these cases: + // 1. When we are in archived chats and no chat or forum is open. + // 2. When we are in any other screen except chat list and archived chat list. + // 3. When we are in chat list and first chat folder is active and no chat or forum is open. + if ((isArchived && noChatOrForumOpen) || (!isChatList && !isArchived) + || (isFirstChatFolderActive && noChatOrForumOpen)) { + return captureEscKeyListener(() => { + handleReset(); + }); + } else { + return undefined; + } + }, [isFirstChatFolderActive, content, handleReset, isChatOpen, isForumPanelOpen], );