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 <noreply@anthropic.com>
This commit is contained in:
Ruslan Bakiev
2026-02-25 07:56:10 +07:00
parent 292d587fe1
commit 6e3763a5fd
3 changed files with 8 additions and 4 deletions

View File

@@ -123,7 +123,7 @@ const {
threadInboxes,
formatInboxLabel,
refetchContactInboxes,
} = useContactInboxes({ apolloAuthReady });
} = useContactInboxes({ apolloAuthReady, onHidden: () => void refetchContacts() });
// ---------------------------------------------------------------------------
// 4. Calendar

View File

@@ -19,7 +19,7 @@ export type ContactInbox = {
updatedAt: string;
};
export function useContactInboxes(opts: { apolloAuthReady: ComputedRef<boolean> }) {
export function useContactInboxes(opts: { apolloAuthReady: ComputedRef<boolean>; onHidden?: () => void }) {
const { result: contactInboxesResult, refetch: refetchContactInboxes } = useQuery(
ContactInboxesQueryDocument,
null,
@@ -60,6 +60,7 @@ export function useContactInboxes(opts: { apolloAuthReady: ComputedRef<boolean>
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 {

View File

@@ -111,8 +111,11 @@ export function useContacts(opts: { apolloAuthReady: ComputedRef<boolean> }) {
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;
}
});