fix(chat): keep sidebar chat selection in sync with the active chat (#26977)
When navigating from a chat to a non-chat route (e.g. the admin panel), the previously-viewed chat stayed selected in the sidebar and deleting/archiving it wrongly redirected back to the new-chat page. Cloning a chat also left the source chat highlighted alongside the new clone, so two chats appeared selected at once. Two independent sources kept the stale selection: - The chatId store was never cleared when the Chat component unmounted, so $chatId still pointed at the last-viewed chat (this drove the delete/archive redirect). Clear chatId/chatTitle in Chat's onDestroy. - The sidebar's optimistic selectedChatId highlight, set on click, was only cleared on window blur (hence it appeared to fix itself after a tab switch) and never followed programmatic navigation. Bind it to the chatId store so it tracks the active chat for leave, delete and clone.
This commit is contained in:
2 files changed
+16
No files matched your search
@@ -1362,6 +1362,13 @@
|
|||||||
pageSubscribe();
|
pageSubscribe();
|
||||||
showControlsSubscribe();
|
showControlsSubscribe();
|
||||||
selectedFolderSubscribe();
|
selectedFolderSubscribe();
|
||||||
|
|
||||||
|
// Clear the selected chat when leaving the chat surface (e.g. navigating
|
||||||
|
// to the admin panel), otherwise the previously-viewed chat stays selected
|
||||||
|
// in the sidebar and deleting/archiving it wrongly navigates away.
|
||||||
|
chatId.set('');
|
||||||
|
chatTitle.set('');
|
||||||
|
|
||||||
window.removeEventListener('message', onMessageHandler);
|
window.removeEventListener('message', onMessageHandler);
|
||||||
$socket?.off('events', chatEventHandler);
|
$socket?.off('events', chatEventHandler);
|
||||||
$socket?.off('connect', handleSocketConnect);
|
$socket?.off('connect', handleSocketConnect);
|
||||||
|
|||||||
@@ -90,6 +90,15 @@
|
|||||||
let shiftKey = false;
|
let shiftKey = false;
|
||||||
|
|
||||||
let selectedChatId = null;
|
let selectedChatId = null;
|
||||||
|
|
||||||
|
// Keep the optimistic sidebar highlight in sync with the active chat. Leaving the
|
||||||
|
// chat view (e.g. navigating to an admin page) clears chatId, and programmatic
|
||||||
|
// navigation such as cloning moves chatId to a different chat — in both cases the
|
||||||
|
// previously-selected item must not stay highlighted. The optimistic on-click
|
||||||
|
// highlight is preserved because a click sets selectedChatId without changing
|
||||||
|
// chatId, so this reactive only re-runs once chatId catches up to the same value.
|
||||||
|
$: selectedChatId = $chatId || null;
|
||||||
|
|
||||||
let showCreateChannel = false;
|
let showCreateChannel = false;
|
||||||
|
|
||||||
// Pagination variables
|
// Pagination variables
|
||||||
|
|||||||
Reference in new issue
Block a user