From 6e3763a5fd8b09182bacc1064d97ca2c7f09ea47 Mon Sep 17 00:00:00 2001 From: Ruslan Bakiev <572431+veikab@users.noreply.github.com> Date: Wed, 25 Feb 2026 07:56:10 +0700 Subject: [PATCH] fix: refetch contacts after hiding inbox, redirect to most recent chat After hiding a contact inbox, the contacts list now refetches immediately so the hidden contact disappears reactively. When the current contact is removed from the list, the selection jumps to the most recently active contact (by lastContactAt) instead of the first item in the current sort. Co-Authored-By: Claude Opus 4.6 --- frontend/app/components/workspace/CrmWorkspaceApp.vue | 2 +- frontend/app/composables/useContactInboxes.ts | 3 ++- frontend/app/composables/useContacts.ts | 7 +++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/frontend/app/components/workspace/CrmWorkspaceApp.vue b/frontend/app/components/workspace/CrmWorkspaceApp.vue index 35ecd4f..d5d236e 100644 --- a/frontend/app/components/workspace/CrmWorkspaceApp.vue +++ b/frontend/app/components/workspace/CrmWorkspaceApp.vue @@ -123,7 +123,7 @@ const { threadInboxes, formatInboxLabel, refetchContactInboxes, -} = useContactInboxes({ apolloAuthReady }); +} = useContactInboxes({ apolloAuthReady, onHidden: () => void refetchContacts() }); // --------------------------------------------------------------------------- // 4. Calendar diff --git a/frontend/app/composables/useContactInboxes.ts b/frontend/app/composables/useContactInboxes.ts index 3c71190..21ea0ff 100644 --- a/frontend/app/composables/useContactInboxes.ts +++ b/frontend/app/composables/useContactInboxes.ts @@ -19,7 +19,7 @@ export type ContactInbox = { updatedAt: string; }; -export function useContactInboxes(opts: { apolloAuthReady: ComputedRef }) { +export function useContactInboxes(opts: { apolloAuthReady: ComputedRef; onHidden?: () => void }) { const { result: contactInboxesResult, refetch: refetchContactInboxes } = useQuery( ContactInboxesQueryDocument, null, @@ -60,6 +60,7 @@ export function useContactInboxes(opts: { apolloAuthReady: ComputedRef inboxToggleLoadingById.value = { ...inboxToggleLoadingById.value, [id]: true }; try { await doSetContactInboxHidden({ inboxId: id, hidden }); + if (hidden && opts.onHidden) opts.onHidden(); } catch (e: unknown) { console.error("[setInboxHidden] mutation failed:", e); } finally { diff --git a/frontend/app/composables/useContacts.ts b/frontend/app/composables/useContacts.ts index f6808e6..73a301a 100644 --- a/frontend/app/composables/useContacts.ts +++ b/frontend/app/composables/useContacts.ts @@ -111,8 +111,11 @@ export function useContacts(opts: { apolloAuthReady: ComputedRef }) { return; } if (!filteredContacts.value.some((item) => item.id === selectedContactId.value)) { - const first = filteredContacts.value[0]; - if (first) selectedContactId.value = first.id; + // Always pick the most recently active contact, regardless of current sort mode + const mostRecent = [...filteredContacts.value].sort((a, b) => + b.lastContactAt.localeCompare(a.lastContactAt), + )[0]; + if (mostRecent) selectedContactId.value = mostRecent.id; } });