diff --git a/static/js/pm_list.js b/static/js/pm_list.js index 2c2a42420a..8a2f02e308 100644 --- a/static/js/pm_list.js +++ b/static/js/pm_list.js @@ -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() { diff --git a/static/js/top_left_corner.js b/static/js/top_left_corner.js index cc1a530143..3b03e6bce8 100644 --- a/static/js/top_left_corner.js +++ b/static/js/top_left_corner.js @@ -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); } diff --git a/static/js/ui_util.js b/static/js/ui_util.js index 95c5377016..0bfa49f6a8 100644 --- a/static/js/ui_util.js +++ b/static/js/ui_util.js @@ -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); +}