From c0ca6d31027978dceb4b1fc9f3d46a0698c64cd2 Mon Sep 17 00:00:00 2001 From: Max Hao Date: Wed, 10 Jun 2026 10:32:52 -0400 Subject: [PATCH] fix: add collapse all threads functionality to email selection in thread list --- components/email/email-list.tsx | 14 +++++- components/email/thread-list-item.tsx | 72 +++++++++++++++------------ 2 files changed, 52 insertions(+), 34 deletions(-) diff --git a/components/email/email-list.tsx b/components/email/email-list.tsx index 5a781e85..bad9db10 100644 --- a/components/email/email-list.tsx +++ b/components/email/email-list.tsx @@ -101,6 +101,7 @@ export function EmailList({ toggleThreadExpansion, fetchThreadEmails, markThreadAsRead, + collapseAllThreads, threadEmailCounts, searchFilters, setSearchFilters, @@ -477,7 +478,18 @@ export function EmailList({ isLoading={isLoadingThread === thread.threadId} expandedEmails={threadEmailsCache.get(thread.threadId)} onToggleExpand={() => handleToggleThreadExpansion(thread.threadId)} - onEmailSelect={(email) => onEmailSelect?.(email)} + onCollapseAllThreads={collapseAllThreads} + onEmailSelect={(email) => { + // Collapse expanded threads when selecting an email outside the expanded thread + const currentExpanded = useEmailStore.getState().expandedThreadIds; + if (currentExpanded.size > 0) { + // Check if the selected email belongs to any expanded thread via its threadId + if (!email.threadId || !currentExpanded.has(email.threadId)) { + collapseAllThreads(); + } + } + onEmailSelect?.(email); + }} onEmailDoubleClick={onEmailDoubleClick ? (email) => onEmailDoubleClick(email) : undefined} onContextMenu={openContextMenu} onOpenConversation={onOpenConversation} diff --git a/components/email/thread-list-item.tsx b/components/email/thread-list-item.tsx index 11e84099..cacc4d83 100644 --- a/components/email/thread-list-item.tsx +++ b/components/email/thread-list-item.tsx @@ -24,6 +24,7 @@ interface ThreadListItemProps { isLoading?: boolean; expandedEmails?: Email[]; onToggleExpand: () => void; + onCollapseAllThreads?: () => void; onEmailSelect: (email: Email) => void; onEmailDoubleClick?: (email: Email) => void; onContextMenu?: (e: React.MouseEvent, email: Email) => void; @@ -384,6 +385,7 @@ export const ThreadListItem = React.forwardRef 0) clearSelection(); if (!isExpanded) { + onCollapseAllThreads?.(); onToggleExpand(); } onEmailSelect(latestEmail); @@ -581,32 +584,6 @@ export const ThreadListItem = React.forwardRef )} - {!isMobile && !isFocusedMailLayout && ( - - )} - {hasUnread && (
@@ -614,13 +591,42 @@ export const ThreadListItem = React.forwardRef +
+ + {!isMobile && !isFocusedMailLayout && ( + + )} +
)}