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.

js: Convert static/js/stream_ui_updates.js to ES6 module.

Anders Kaseorg4360a13dd6e0
diff --git a/.eslintrc.json b/.eslintrc.json
index 4c2d674543c..ab7a491ac0d 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -259,7 +259,6 @@
"stream_list": false,
"stream_muting": false,
"stream_popover": false,
- "stream_ui_updates": false,
"StripeCheckout": false,
"submessage": false,
"subs": false,
diff --git a/frontend_tests/node_tests/stream_edit.js b/frontend_tests/node_tests/stream_edit.js
index 4549311a5b5..20ab884bf2d 100644
--- a/frontend_tests/node_tests/stream_edit.js
+++ b/frontend_tests/node_tests/stream_edit.js
@@ -26,9 +26,6 @@ set_global("settings_notifications", {
set_global("stream_color", {
set_colorpicker_color: noop,
});
-set_global("stream_ui_updates", {
- update_add_subscriptions_elements: noop,
-});
const typeahead_helper = set_global("typeahead_helper", {});
const ui = set_global("ui", {
get_scroll_element: noop,
diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js
index 89b77563897..a84fe78fe0f 100644
--- a/static/js/bundles/app.js
+++ b/static/js/bundles/app.js
@@ -154,7 +154,6 @@ import "../compose_ui";
import "../panels";
import "../recent_topics";
import "../search_pill_widget";
-import "../stream_ui_updates";
import "../spoilers";
import "../desktop_integration";
diff --git a/static/js/global.d.ts b/static/js/global.d.ts
index 2911431d796..0f42d8cac66 100644
--- a/static/js/global.d.ts
+++ b/static/js/global.d.ts
@@ -125,7 +125,6 @@ declare let stream_events: any;
declare let stream_list: any;
declare let stream_muting: any;
declare let stream_popover: any;
-declare let stream_ui_updates: any;
declare let submessage: any;
declare let subs: any;
declare let message_view_header: any;
diff --git a/static/js/notifications.js b/static/js/notifications.js
index 0d6074998c7..176255d40f3 100644
--- a/static/js/notifications.js
+++ b/static/js/notifications.js
@@ -9,6 +9,7 @@ const alert_words = require("./alert_words");
const favicon = require("./favicon");
const people = require("./people");
const settings_config = require("./settings_config");
+const stream_ui_updates = require("./stream_ui_updates");
const notice_memory = new Map();
diff --git a/static/js/stream_edit.js b/static/js/stream_edit.js
index 840bf6dcd5e..71d09ccd273 100644
--- a/static/js/stream_edit.js
+++ b/static/js/stream_edit.js
@@ -13,6 +13,7 @@ const settings_config = require("./settings_config");
const settings_data = require("./settings_data");
const settings_ui = require("./settings_ui");
const stream_pill = require("./stream_pill");
+const stream_ui_updates = require("./stream_ui_updates");
const util = require("./util");
function setup_subscriptions_stream_hash(sub) {
diff --git a/static/js/stream_ui_updates.js b/static/js/stream_ui_updates.js
index ea55b79c972..8f2b65ddf2d 100644
--- a/static/js/stream_ui_updates.js
+++ b/static/js/stream_ui_updates.js
@@ -1,12 +1,10 @@
-"use strict";
+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";
-const render_subscription_count = require("../templates/subscription_count.hbs");
-const render_subscription_setting_icon = require("../templates/subscription_setting_icon.hbs");
-const render_subscription_type = require("../templates/subscription_type.hbs");
+import * as peer_data from "./peer_data";
-const peer_data = require("./peer_data");
-
-exports.update_check_button_for_sub = function (sub) {
+export function update_check_button_for_sub(sub) {
const button = subs.check_button_for_sub(sub);
if (sub.subscribed) {
button.addClass("checked");
@@ -18,9 +16,9 @@ exports.update_check_button_for_sub = function (sub) {
} else {
button.addClass("disabled");
}
-};
+}
-exports.initialize_disable_btn_hint_popover = function (
+export function initialize_disable_btn_hint_popover(
btn_wrapper,
popover_btn,
disabled_btn,
@@ -47,20 +45,20 @@ exports.initialize_disable_btn_hint_popover = function (
popover_btn.popover("hide");
e.stopPropagation();
});
-};
+}
-exports.initialize_cant_subscribe_popover = function (sub) {
+export function initialize_cant_subscribe_popover(sub) {
const button_wrapper = stream_edit.settings_for_sub(sub).find(".sub_unsub_button_wrapper");
const settings_button = subs.settings_button_for_sub(sub);
- exports.initialize_disable_btn_hint_popover(
+ initialize_disable_btn_hint_popover(
button_wrapper,
settings_button,
settings_button,
i18n.t("Only stream members can add users to a private stream"),
);
-};
+}
-exports.update_settings_button_for_sub = function (sub) {
+export function update_settings_button_for_sub(sub) {
const settings_button = subs.settings_button_for_sub(sub);
if (sub.subscribed) {
settings_button.text(i18n.t("Unsubscribe")).removeClass("unsubscribed");
@@ -73,12 +71,12 @@ exports.update_settings_button_for_sub = function (sub) {
settings_button.css("pointer-events", "");
} else {
settings_button.attr("title", "");
- exports.initialize_cant_subscribe_popover(sub);
+ initialize_cant_subscribe_popover(sub);
settings_button.prop("disabled", true);
}
-};
+}
-exports.update_regular_sub_settings = function (sub) {
+export function update_regular_sub_settings(sub) {
if (!stream_edit.is_sub_settings_active(sub)) {
return;
}
@@ -95,9 +93,9 @@ exports.update_regular_sub_settings = function (sub) {
// Clear email address widget
$settings.find(".email-address").html("");
}
-};
+}
-exports.update_change_stream_privacy_settings = function (sub) {
+export function update_change_stream_privacy_settings(sub) {
const stream_privacy_btn = $(".change-stream-privacy");
if (sub.can_change_stream_permissions) {
@@ -105,9 +103,9 @@ exports.update_change_stream_privacy_settings = function (sub) {
} else {
stream_privacy_btn.hide();
}
-};
+}
-exports.update_notification_setting_checkbox = function (notification_name) {
+export function update_notification_setting_checkbox(notification_name) {
const stream_row = $("#subscriptions_table .stream-row.active");
if (!stream_row.length) {
return;
@@ -117,9 +115,9 @@ exports.update_notification_setting_checkbox = function (notification_name) {
"checked",
stream_data.receives_notifications(stream_id, notification_name),
);
-};
+}
-exports.update_stream_row_in_settings_tab = function (sub) {
+export function update_stream_row_in_settings_tab(sub) {
// This function display/hide stream row in stream settings tab,
// used to display immediate effect of add/removal subscription event.
// If user is subscribed to stream, it will show sub row under
@@ -133,9 +131,9 @@ exports.update_stream_row_in_settings_tab = function (sub) {
sub_row.addClass("notdisplayed");
}
}
-};
+}
-exports.update_stream_privacy_type_icon = function (sub) {
+export function update_stream_privacy_type_icon(sub) {
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);
@@ -154,9 +152,9 @@ exports.update_stream_privacy_type_icon = function (sub) {
large_icon.addClass("hash").removeClass("lock").html("");
}
}
-};
+}
-exports.update_stream_subscription_type_text = function (sub) {
+export function update_stream_subscription_type_text(sub) {
const stream_settings = stream_edit.settings_for_sub(sub);
const template_data = {
...sub,
@@ -167,9 +165,9 @@ exports.update_stream_subscription_type_text = function (sub) {
if (stream_edit.is_sub_settings_active(sub)) {
stream_settings.find(".subscription-type-text").expectOne().html(html);
}
-};
+}
-exports.update_subscribers_count = function (sub, just_subscribed) {
+export function update_subscribers_count(sub, just_subscribed) {
if (!overlays.streams_open()) {
// If the streams overlay isn't open, we don't need to rerender anything.
return;
@@ -191,9 +189,9 @@ exports.update_subscribers_count = function (sub, just_subscribed) {
} else {
stream_row.find(".subscriber-count-text").expectOne().text(sub_count);
}
-};
+}
-exports.update_subscribers_list = function (sub) {
+export function update_subscribers_list(sub) {
// Render subscriptions only if stream settings is open
if (!stream_edit.is_sub_settings_active(sub)) {
return;
@@ -223,9 +221,9 @@ exports.update_subscribers_list = function (sub) {
}
$(".subscriber_list_settings_container").show();
}
-};
+}
-exports.update_add_subscriptions_elements = function (sub) {
+export function update_add_subscriptions_elements(sub) {
if (!stream_edit.is_sub_settings_active(sub)) {
return;
}
@@ -253,13 +251,11 @@ exports.update_add_subscriptions_elements = function (sub) {
input_element.prop("disabled", true);
button_element.prop("disabled", true);
- exports.initialize_disable_btn_hint_popover(
+ initialize_disable_btn_hint_popover(
$(".add_subscribers_container"),
input_element,
button_element,
i18n.t("Only stream members can add users to a private stream"),
);
}
-};
-
-window.stream_ui_updates = exports;
+}
diff --git a/static/js/subs.js b/static/js/subs.js
index 77b12a81678..6f1e2e71f63 100644
--- a/static/js/subs.js
+++ b/static/js/subs.js
@@ -11,6 +11,7 @@ const components = require("./components");
const people = require("./people");
const search_util = require("./search_util");
const stream_create = require("./stream_create");
+const stream_ui_updates = require("./stream_ui_updates");
const util = require("./util");
exports.show_subs_pane = {