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; } });