Calm down sidebar refreshes with better contact don't-set behavior, unread count checks, and memoized sorting etc.

This commit is contained in:
Jack Kingsman
2026-02-13 00:00:53 -08:00
parent 430b5aaba7
commit 57d007dec2
3 changed files with 159 additions and 121 deletions
+7 -3
View File
@@ -55,11 +55,15 @@ export function useUnreadCounts(
}
}, []);
// Fetch when channels or contacts arrive/change
// Fetch when the number of channels/contacts changes (e.g. initial load,
// sync, create/delete). Using .length avoids refiring on every WebSocket
// contact-update that merely mutates an existing entry's fields.
const channelsLen = channels.length;
const contactsLen = contacts.length;
useEffect(() => {
if (channels.length === 0 && contacts.length === 0) return;
if (channelsLen === 0 && contactsLen === 0) return;
fetchUnreads();
}, [channels, contacts, fetchUnreads]);
}, [channelsLen, contactsLen, fetchUnreads]);
// Mark conversation as read when user views it
// Calls server API to persist read state across devices