Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

stream settings: Simplify live-updates for left panel.

Steve Howellc3ee1286f44f
diff --git a/static/js/stream_ui_updates.js b/static/js/stream_ui_updates.js
index f9f1df1a387..d6212857b0e 100644
--- a/static/js/stream_ui_updates.js
+++ b/static/js/stream_ui_updates.js
@@ -1,28 +1,7 @@
-import render_subscription_count from "../templates/subscription_count.hbs";
-import render_subscription_setting_icon from "../templates/subscription_setting_icon.hbs";
import render_subscription_type from "../templates/subscription_type.hbs";
import * as peer_data from "./peer_data";
-export function update_check_button_for_sub(sub) {
- /*
- TODO: remove update_check_button_for_sub
-
- <div class="check {{#if subscribed }}checked{{/if}} sub_unsub_button {{#unless should_display_subscription_button}}disabled{{/unless}}">
- */
- const button = subs.check_button_for_sub(sub);
- if (sub.subscribed) {
- button.addClass("checked");
- } else {
- button.removeClass("checked");
- }
- if (sub.should_display_subscription_button) {
- button.removeClass("disabled");
- } else {
- button.addClass("disabled");
- }
-}
-
export function initialize_disable_btn_hint_popover(
btn_wrapper,
popover_btn,
@@ -143,39 +122,6 @@ export function update_stream_row_in_settings_tab(sub) {
}
}
-export function update_stream_privacy_type_icon(sub) {
- /*
- TODO: remove update_stream_privacy_type_icon
-
- {{#if invite_only}}
- <i class="fa fa-lock" aria-hidden="true"></i>
- {{else if is_web_public}}
- <i class="fa fa-globe fa-lg" aria-hidden="true"></i>
- {{else}}
- <span class="hashtag">#</span>
- {{/if}}
-
- */
- const stream_settings = stream_edit.settings_for_sub(sub);
- const sub_row = subs.row_for_stream_id(sub.stream_id);
- const html = render_subscription_setting_icon(sub);
-
- if (overlays.streams_open()) {
- sub_row.find(".icon").expectOne().replaceWith($(html));
- }
- if (stream_edit.is_sub_settings_active(sub)) {
- const large_icon = stream_settings.find(".large-icon").expectOne();
- if (sub.invite_only) {
- large_icon
- .removeClass("hash")
- .addClass("lock")
- .html("<i class='fa fa-lock' aria-hidden='true'></i>");
- } else {
- large_icon.addClass("hash").removeClass("lock").html("");
- }
- }
-}
-
export function update_stream_subscription_type_text(sub) {
// This is in the right panel.
const stream_settings = stream_edit.settings_for_sub(sub);
@@ -190,45 +136,6 @@ export function update_stream_subscription_type_text(sub) {
}
}
-export function update_subscribers_count(sub, just_subscribed) {
- /*
- TODO: remove update_subscribers_count
-
- <div class="subscriber-count" data-toggle="tooltip" title="{{t 'Subscriber count' }}">
- {{> subscription_count}}
- </div>
-
- <i class="fa fa-user-o" aria-hidden="true"></i>
- {{#if can_access_subscribers}}
- <span class="subscriber-count-text">{{numberFormat subscriber_count}}</span>
- {{else}}
- <i class="subscriber-count-lock fa fa-lock" aria-hidden="true"></i>
- {{/if}}
- */
-
- if (!overlays.streams_open()) {
- // If the streams overlay isn't open, we don't need to rerender anything.
- return;
- }
-
- const stream_row = subs.row_for_stream_id(sub.stream_id);
- const sub_count = peer_data.get_subscriber_count(sub.stream_id);
-
- if (
- !sub.can_access_subscribers ||
- (just_subscribed && sub.invite_only) ||
- page_params.is_guest
- ) {
- const rendered_sub_count = render_subscription_count({
- can_access_subscribers: sub.can_access_subscribers,
- subscriber_count: sub_count,
- });
- stream_row.find(".subscriber-count").expectOne().html(rendered_sub_count);
- } else {
- stream_row.find(".subscriber-count-text").expectOne().text(sub_count);
- }
-}
-
export function update_subscribers_list(sub) {
// This is for the "Stream membership" section of the right panel.
// Render subscriptions only if stream settings is open
diff --git a/static/js/subs.js b/static/js/subs.js
index 5a0eb02038a..c3066d0d599 100644
--- a/static/js/subs.js
+++ b/static/js/subs.js
@@ -29,11 +29,6 @@ exports.show_subs_pane = {
},
};
-exports.check_button_for_sub = function (sub) {
- // TODO: remove check_button_for_sub
- return $(`.stream-row[data-stream-id='${CSS.escape(sub.stream_id)}'] .check`);
-};
-
exports.row_for_stream_id = function (stream_id) {
return $(`.stream-row[data-stream-id='${CSS.escape(stream_id)}']`);
};
@@ -42,6 +37,33 @@ exports.is_sub_already_present = function (sub) {
return exports.row_for_stream_id(sub.stream_id).length > 0;
};
+exports.update_left_panel_row = (sub) => {
+ const row = exports.row_for_stream_id(sub.stream_id);
+
+ if (row.length === 0) {
+ return;
+ }
+
+ blueslip.debug(`Updating row in left panel of stream settings for: ${sub.name}`);
+ const setting_sub = stream_data.get_sub_for_settings(sub);
+ const html = render_subscription(setting_sub);
+ const new_row = $(html);
+
+ // TODO: Clean up this hack when we eliminate `notdisplayed`
+ if (row.hasClass("notdisplayed")) {
+ new_row.addClass("notdisplayed");
+ }
+
+ // TODO: Remove this if/when we just handle "active" when rendering templates.
+ if (row.hasClass("active")) {
+ new_row.addClass("active");
+ }
+
+ exports.add_tooltip_to_left_panel_row(new_row);
+
+ row.replaceWith(new_row);
+};
+
exports.settings_button_for_sub = function (sub) {
// We don't do expectOne() here, because this button is only
// visible if the user has that stream selected in the streams UI.
@@ -188,11 +210,10 @@ exports.update_stream_privacy = function (sub, values) {
stream_data.update_calculated_fields(sub);
// Update UI elements
- stream_ui_updates.update_stream_privacy_type_icon(sub);
+ exports.update_left_panel_row(sub);
stream_ui_updates.update_stream_subscription_type_text(sub);
stream_ui_updates.update_change_stream_privacy_settings(sub);
stream_ui_updates.update_settings_button_for_sub(sub);
- stream_ui_updates.update_subscribers_count(sub);
stream_ui_updates.update_add_subscriptions_elements(sub);
stream_list.redraw_stream_privacy(sub);
@@ -218,7 +239,7 @@ exports.set_color = function (stream_id, color) {
};
exports.update_subscribers_ui = function (sub) {
- stream_ui_updates.update_subscribers_count(sub);
+ exports.update_left_panel_row(sub);
stream_ui_updates.update_subscribers_list(sub);
message_view_header.maybe_rerender_title_area_for_stream(sub);
};
@@ -282,9 +303,8 @@ exports.update_settings_for_subscribed = function (sub) {
).show();
if (exports.is_sub_already_present(sub)) {
+ exports.update_left_panel_row(sub);
stream_ui_updates.update_stream_row_in_settings_tab(sub);
- stream_ui_updates.update_subscribers_count(sub, true);
- stream_ui_updates.update_check_button_for_sub(sub);
stream_ui_updates.update_settings_button_for_sub(sub);
stream_ui_updates.update_change_stream_privacy_settings(sub);
} else {
@@ -314,9 +334,8 @@ exports.add_tooltip_to_left_panel_row = (row) => {
};
exports.update_settings_for_unsubscribed = function (sub) {
- stream_ui_updates.update_subscribers_count(sub);
+ exports.update_left_panel_row(sub);
stream_ui_updates.update_subscribers_list(sub);
- stream_ui_updates.update_check_button_for_sub(sub);
stream_ui_updates.update_settings_button_for_sub(sub);
stream_ui_updates.update_regular_sub_settings(sub);
stream_ui_updates.update_change_stream_privacy_settings(sub);