From ab2e7e097a4cf0c8ca3bd73e9380b58b06f7030a Mon Sep 17 00:00:00 2001 From: YashRE42 <33805964+YashRE42@users.noreply.github.com> Date: Tue, 16 Jun 2020 17:20:22 +0000 Subject: [PATCH] navbar: Switch make_tab_bar conditionals to using filter/sub values. Previously, this function relied on the return value of `filter.get_icon()` which made it brittle. Directly using the properties of the filter and sub object makes this more explicit about the intentions and robust. --- static/js/tab_bar.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/static/js/tab_bar.js b/static/js/tab_bar.js index df8a87bdef..4a9782ab9e 100644 --- a/static/js/tab_bar.js +++ b/static/js/tab_bar.js @@ -25,13 +25,16 @@ function make_tab_data(filter) { } tab_data.title = filter.get_title(); tab_data.icon = filter.get_icon(); - if (tab_data.icon === 'question-circle-o') { + if (filter.has_operator('stream') && !filter._sub) { tab_data.sub_count = '0'; tab_data.formatted_sub_count = '0'; tab_data.rendered_narrow_description = i18n.t("This stream does not exist or is private."); return tab_data; } - if (['hashtag', 'lock', 'globe'].includes(tab_data.icon)) { + if (filter._sub) { + // We can now be certain that the narrow + // involves a stream which exists and + // the current user can access. const stream = filter.operands("stream")[0]; // We can rely on current_stream because if the stream doesn't // exist then the "question-circle-o" case would case early exit.