top_left_corner: Extract function which updates unread count.

This is a common element that is being used both by pm_list and
top_left_corner, hence extraction makes sense.
This commit is contained in:
Aman Agrawal 2021-04-09 07:18:43 +00:00 committed by Tim Abbott
parent b1f8041c31
commit 79bf740dcb
3 changed files with 22 additions and 30 deletions

View File

@ -10,6 +10,7 @@ import * as stream_popover from "./stream_popover";
import * as ui from "./ui";
import * as unread from "./unread";
import * as vdom from "./vdom";
import * as ui_util from "./ui_util";
let prior_dom;
let private_messages_open = false;
@ -26,20 +27,8 @@ function get_filter_li() {
return $(".top_left_private_messages");
}
function update_count_in_dom(count_span, value_span, count) {
if (count === 0) {
count_span.hide();
value_span.text("");
} else {
count_span.show();
value_span.text(count);
}
}
function set_count(count) {
const count_span = get_filter_li().find(".count");
const value_span = count_span.find(".value");
update_count_in_dom(count_span, value_span, count);
ui_util.update_unread_count_in_dom(get_filter_li(), count);
}
function remove_expanded_private_messages() {

View File

@ -4,24 +4,11 @@ import * as people from "./people";
import * as pm_list from "./pm_list";
import * as resize from "./resize";
import * as unread_ui from "./unread_ui";
export function update_count_in_dom(unread_count_elem, count) {
const count_span = unread_count_elem.find(".count");
const value_span = count_span.find(".value");
if (count === 0) {
count_span.hide();
value_span.text("");
return;
}
count_span.show();
value_span.text(count);
}
import * as ui_util from "./ui_util";
export function update_starred_count(count) {
const starred_li = $(".top_left_starred_messages");
update_count_in_dom(starred_li, count);
ui_util.update_unread_count_in_dom(starred_li, count);
}
export function update_dom_with_unread_counts(counts) {
@ -31,8 +18,8 @@ export function update_dom_with_unread_counts(counts) {
const mentioned_li = $(".top_left_mentions");
const home_li = $(".top_left_all_messages");
update_count_in_dom(mentioned_li, counts.mentioned_message_count);
update_count_in_dom(home_li, counts.home_unread_messages);
ui_util.update_unread_count_in_dom(mentioned_li, counts.mentioned_message_count);
ui_util.update_unread_count_in_dom(home_li, counts.home_unread_messages);
unread_ui.animate_mention_changes(mentioned_li, counts.mentioned_message_count);
}

View File

@ -38,3 +38,19 @@ export function convert_enter_to_click(e) {
$(e.currentTarget).trigger("click");
}
}
export function update_unread_count_in_dom(unread_count_elem, count) {
// This function is used to update unread count in top left corner
// elements.
const count_span = unread_count_elem.find(".count");
const value_span = count_span.find(".value");
if (count === 0) {
count_span.hide();
value_span.text("");
return;
}
count_span.show();
value_span.text(count);
}