narrow: Use update_current_message_list instead of set_current.

It's important to remove the focused class and remote the
old message list from DOM which only happens in
update_current_message_list.
This commit is contained in:
Aman Agrawal
2024-02-05 11:59:04 +00:00
committed by Tim Abbott
parent 3c0cb4c6a2
commit 4ccf64b02b
5 changed files with 27 additions and 22 deletions

View File

@@ -55,10 +55,25 @@ export type MessageList = {
export let home: MessageList | undefined;
export let current: MessageList | undefined;
export function set_current(msg_list: MessageList): void {
function set_current(msg_list: MessageList): void {
// NOTE: Use update_current_message_list instead of this function.
current = msg_list;
}
export function update_current_message_list(msg_list: MessageList): void {
if (msg_list !== home) {
home?.view.$list.removeClass("focused-message-list");
}
if (current !== home) {
// Remove old msg list from DOM.
current?.view.$list.remove();
}
set_current(msg_list);
current?.view.$list.addClass("focused-message-list");
}
export function set_home(msg_list: MessageList): void {
home = msg_list;
}