From adb831b8c315e78354d514a05a1c20fd94d1b3a7 Mon Sep 17 00:00:00 2001 From: Immad Abdul Jabbar Date: Fri, 17 Jan 2025 23:19:10 +0500 Subject: [PATCH] fix: conversation removal from custom folder [WPB-15352] --- .../conversation/ConversationLabelRepository.ts | 13 +++++++++++-- .../panels/Conversations/Conversations.tsx | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/script/conversation/ConversationLabelRepository.ts b/src/script/conversation/ConversationLabelRepository.ts index 27fc60ee936..0cc886c6858 100644 --- a/src/script/conversation/ConversationLabelRepository.ts +++ b/src/script/conversation/ConversationLabelRepository.ts @@ -244,10 +244,19 @@ export class ConversationLabelRepository extends TypedEventTarget<{type: 'conver .sort(({name: nameA}, {name: nameB}) => nameA.localeCompare(nameB, undefined, {sensitivity: 'base'})); readonly removeConversationFromLabel = (label: ConversationLabel, removeConversation: Conversation): void => { - label.conversations(label.conversations().filter(conversation => conversation !== removeConversation)); - const {setCurrentTab} = useSidebarStore.getState(); + // Remove conversation from folder and update folder in labels + const folderIndex = this.labels.indexOf(label); + const updatedFolder = createLabel( + label.name, + label.conversations().filter(conversation => conversation !== removeConversation), + label.id, + label.type, + ); + + this.labels.splice(folderIndex, 1, updatedFolder); + // Delete folder if it no longer contains any conversation if (!label.conversations().length) { this.labels.remove(label); diff --git a/src/script/page/LeftSidebar/panels/Conversations/Conversations.tsx b/src/script/page/LeftSidebar/panels/Conversations/Conversations.tsx index 7719b9ef94e..783f79eeb19 100644 --- a/src/script/page/LeftSidebar/panels/Conversations/Conversations.tsx +++ b/src/script/page/LeftSidebar/panels/Conversations/Conversations.tsx @@ -133,6 +133,7 @@ export const Conversations: React.FC = ({ const {activeCalls} = useKoSubscribableChildren(callState, ['activeCalls']); const {conversationLabelRepository} = conversationRepository; + const {labels} = useKoSubscribableChildren(conversationLabelRepository, ['labels']); const favoriteConversations = useMemo( () => conversationLabelRepository.getFavorites(conversations), [conversationLabelRepository, conversations], @@ -177,8 +178,7 @@ export const Conversations: React.FC = ({ favoriteConversations, }); - const currentFolder = conversationLabelRepository - .getLabels() + const currentFolder = labels .map(label => createLabel(label.name, conversationLabelRepository.getLabelConversations(label), label.id)) .find(folder => folder.id === expandedFolder);