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/avatar.js to ES6 module.

Anders Kaseorgb2849edfd70a
diff --git a/.eslintrc.json b/.eslintrc.json
index ac56476db77..1760a3ad930 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -126,7 +126,6 @@
"globals": {
"$": false,
"admin": false,
- "avatar": false,
"blueslip": false,
"bot_data": false,
"compose_actions": false,
diff --git a/frontend_tests/node_tests/settings_bots.js b/frontend_tests/node_tests/settings_bots.js
index 206b9f7dff8..d9208d22bf4 100644
--- a/frontend_tests/node_tests/settings_bots.js
+++ b/frontend_tests/node_tests/settings_bots.js
@@ -29,7 +29,9 @@ const bot_data_params = {
],
};
-const avatar = set_global("avatar", {});
+const avatar = {__esModule: true};
+
+rewiremock("../../static/js/avatar").with(avatar);
function ClipboardJS(sel) {
assert.equal(sel, "#copy_zuliprc");
diff --git a/static/js/avatar.js b/static/js/avatar.js
index a39e22e64c2..0ccc34144a5 100644
--- a/static/js/avatar.js
+++ b/static/js/avatar.js
@@ -1,9 +1,7 @@
-"use strict";
+import * as channel from "./channel";
+import * as upload_widget from "./upload_widget";
-const channel = require("./channel");
-const upload_widget = require("./upload_widget");
-
-exports.build_bot_create_widget = function () {
+export function build_bot_create_widget() {
// We have to do strange gyrations with the file input to clear it,
// where we replace it wholesale, so we generalize the file input with
// a callback function.
@@ -23,9 +21,9 @@ exports.build_bot_create_widget = function () {
clear_button,
upload_button,
);
-};
+}
-exports.build_bot_edit_widget = function (target) {
+export function build_bot_edit_widget(target) {
const get_file_input = function () {
return target.find(".edit_bot_avatar_file_input");
};
@@ -42,9 +40,9 @@ exports.build_bot_edit_widget = function (target) {
clear_button,
upload_button,
);
-};
+}
-exports.build_user_avatar_widget = function (upload_function) {
+export function build_user_avatar_widget(upload_function) {
const get_file_input = function () {
return $("#user-avatar-upload-widget .image_file_input").expectOne();
};
@@ -83,6 +81,4 @@ exports.build_user_avatar_widget = function (upload_function) {
}
return undefined;
-};
-
-window.avatar = exports;
+}
diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js
index 8a201188ad0..b7db2fba6c5 100644
--- a/static/js/bundles/app.js
+++ b/static/js/bundles/app.js
@@ -34,7 +34,6 @@ import "../message_events";
import "../server_events";
import "../zulip";
import "../templates";
-import "../avatar";
import "../realm_icon";
import "../realm_logo";
import "../reminder";
diff --git a/static/js/global.d.ts b/static/js/global.d.ts
index fb9e7553c66..aab305e0cd4 100644
--- a/static/js/global.d.ts
+++ b/static/js/global.d.ts
@@ -4,7 +4,6 @@
// to TS.
declare let admin: any;
-declare let avatar: any;
declare let blueslip: any;
declare let bot_data: any;
declare let compose_actions: any;
diff --git a/static/js/settings_account.js b/static/js/settings_account.js
index 3236ccdae85..8d324af6b20 100644
--- a/static/js/settings_account.js
+++ b/static/js/settings_account.js
@@ -6,6 +6,7 @@ const render_settings_api_key_modal = require("../templates/settings/api_key_mod
const render_settings_custom_user_profile_field = require("../templates/settings/custom_user_profile_field.hbs");
const render_settings_dev_env_email_access = require("../templates/settings/dev_env_email_access.hbs");
+const avatar = require("./avatar");
const channel = require("./channel");
const common = require("./common");
const overlays = require("./overlays");
diff --git a/static/js/settings_bots.js b/static/js/settings_bots.js
index 82f7c493eed..26615f1aeee 100644
--- a/static/js/settings_bots.js
+++ b/static/js/settings_bots.js
@@ -7,6 +7,7 @@ const render_edit_bot = require("../templates/edit_bot.hbs");
const render_settings_edit_embedded_bot_service = require("../templates/settings/edit_embedded_bot_service.hbs");
const render_settings_edit_outgoing_webhook_service = require("../templates/settings/edit_outgoing_webhook_service.hbs");
+const avatar = require("./avatar");
const channel = require("./channel");
const loading = require("./loading");
const overlays = require("./overlays");