Skip to content

Commit

Permalink
fix: conversation removal from custom folder [WPB-15352]
Browse files Browse the repository at this point in the history
  • Loading branch information
e-maad authored Jan 17, 2025
1 parent 1b02a48 commit adb831b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/script/conversation/ConversationLabelRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export const Conversations: React.FC<ConversationsProps> = ({
const {activeCalls} = useKoSubscribableChildren(callState, ['activeCalls']);

const {conversationLabelRepository} = conversationRepository;
const {labels} = useKoSubscribableChildren(conversationLabelRepository, ['labels']);
const favoriteConversations = useMemo(
() => conversationLabelRepository.getFavorites(conversations),
[conversationLabelRepository, conversations],
Expand Down Expand Up @@ -177,8 +178,7 @@ export const Conversations: React.FC<ConversationsProps> = ({
favoriteConversations,
});

const currentFolder = conversationLabelRepository
.getLabels()
const currentFolder = labels
.map(label => createLabel(label.name, conversationLabelRepository.getLabelConversations(label), label.id))
.find(folder => folder.id === expandedFolder);

Expand Down

0 comments on commit adb831b

Please sign in to comment.