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

Anders Kaseorg4c377487127a
diff --git a/.eslintrc.json b/.eslintrc.json
index 9af8dc2b7b0..76de6c3cc56 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -291,7 +291,6 @@
"user_events": false,
"user_groups": false,
"user_pill": false,
- "user_status_ui": false,
"poll_widget": false,
"vdom": false,
"widgetize": false,
diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.js
index fe72ae7628b..9fb943d2787 100644
--- a/frontend_tests/node_tests/ui_init.js
+++ b/frontend_tests/node_tests/ui_init.js
@@ -119,7 +119,6 @@ zrequire("sent_messages");
zrequire("typing");
zrequire("top_left_corner");
zrequire("starred_messages");
-zrequire("user_status_ui");
const ui_init = rewiremock.proxy(() => zrequire("ui_init"), {
"../../static/js/emojisets": {
diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js
index e0df06c7dc3..0ba490f83a6 100644
--- a/static/js/bundles/app.js
+++ b/static/js/bundles/app.js
@@ -112,7 +112,6 @@ import "../message_fetch";
import "../server_events";
import "../zulip";
import "../presence";
-import "../user_status_ui";
import "../buddy_data";
import "../padded_widget";
import "../buddy_list";
diff --git a/static/js/click_handlers.js b/static/js/click_handlers.js
index 63795f1301f..522f990f499 100644
--- a/static/js/click_handlers.js
+++ b/static/js/click_handlers.js
@@ -10,6 +10,7 @@ const render_buddy_list_tooltip_content = require("../templates/buddy_list_toolt
const message_edit_history = require("./message_edit_history");
const settings_panel_menu = require("./settings_panel_menu");
+const user_status_ui = require("./user_status_ui");
const util = require("./util");
function convert_enter_to_click(e) {
diff --git a/static/js/global.d.ts b/static/js/global.d.ts
index 3246563424a..439008cae1c 100644
--- a/static/js/global.d.ts
+++ b/static/js/global.d.ts
@@ -156,5 +156,4 @@ declare let upload_widget: any;
declare let user_events: any;
declare let user_groups: any;
declare let user_pill: any;
-declare let user_status_ui: any;
declare let widgetize: any;
diff --git a/static/js/popovers.js b/static/js/popovers.js
index 01cf81021d0..b3830dd2b65 100644
--- a/static/js/popovers.js
+++ b/static/js/popovers.js
@@ -22,6 +22,7 @@ const people = require("./people");
const settings_config = require("./settings_config");
const settings_data = require("./settings_data");
const user_status = require("./user_status");
+const user_status_ui = require("./user_status_ui");
const util = require("./util");
let current_actions_popover_elem;
diff --git a/static/js/ui_init.js b/static/js/ui_init.js
index e6ad2592904..de0e24f3cfb 100644
--- a/static/js/ui_init.js
+++ b/static/js/ui_init.js
@@ -18,6 +18,7 @@ const people = require("./people");
const pm_conversations = require("./pm_conversations");
const topic_zoom = require("./topic_zoom");
const user_status = require("./user_status");
+const user_status_ui = require("./user_status_ui");
// This is where most of our initialization takes place.
// TODO: Organize it a lot better. In particular, move bigger
diff --git a/static/js/user_status_ui.js b/static/js/user_status_ui.js
index fbaa910bb72..b4d508584de 100644
--- a/static/js/user_status_ui.js
+++ b/static/js/user_status_ui.js
@@ -1,17 +1,15 @@
-"use strict";
+import * as people from "./people";
+import * as user_status from "./user_status";
-const people = require("./people");
-const user_status = require("./user_status");
-
-exports.input_field = function () {
+export function input_field() {
return $(".user_status_overlay input.user_status");
-};
+}
-exports.submit_button = function () {
+export function submit_button() {
return $(".user_status_overlay .set_user_status");
-};
+}
-exports.open_overlay = function () {
+export function open_overlay() {
const overlay = $(".user_status_overlay");
overlays.open_overlay({
name: "user_status_overlay",
@@ -21,89 +19,87 @@ exports.open_overlay = function () {
const user_id = people.my_current_user_id();
const old_status_text = user_status.get_status_text(user_id);
- const field = exports.input_field();
+ const field = input_field();
field.val(old_status_text);
field.trigger("select");
field.trigger("focus");
- exports.toggle_clear_message_button();
+ toggle_clear_message_button();
- const button = exports.submit_button();
+ const button = submit_button();
button.prop("disabled", true);
-};
+}
-exports.close_overlay = function () {
+export function close_overlay() {
overlays.close_overlay("user_status_overlay");
-};
+}
-exports.submit_new_status = function () {
+export function submit_new_status() {
const user_id = people.my_current_user_id();
let old_status_text = user_status.get_status_text(user_id) || "";
old_status_text = old_status_text.trim();
- const new_status_text = exports.input_field().val().trim();
+ const new_status_text = input_field().val().trim();
if (old_status_text === new_status_text) {
- exports.close_overlay();
+ close_overlay();
return;
}
user_status.server_update({
status_text: new_status_text,
success() {
- exports.close_overlay();
+ close_overlay();
},
});
-};
+}
-exports.update_button = function () {
+export function update_button() {
const user_id = people.my_current_user_id();
let old_status_text = user_status.get_status_text(user_id) || "";
old_status_text = old_status_text.trim();
- const new_status_text = exports.input_field().val().trim();
- const button = exports.submit_button();
+ const new_status_text = input_field().val().trim();
+ const button = submit_button();
if (old_status_text === new_status_text) {
button.prop("disabled", true);
} else {
button.prop("disabled", false);
}
-};
+}
-exports.toggle_clear_message_button = function () {
- if (exports.input_field().val() !== "") {
+export function toggle_clear_message_button() {
+ if (input_field().val() !== "") {
$("#clear_status_message_button").prop("disabled", false);
} else {
$("#clear_status_message_button").prop("disabled", true);
}
-};
+}
-exports.clear_message = function () {
- const field = exports.input_field();
+export function clear_message() {
+ const field = input_field();
field.val("");
$("#clear_status_message_button").prop("disabled", true);
-};
+}
-exports.initialize = function () {
+export function initialize() {
$("body").on("click", ".user_status_overlay .set_user_status", () => {
- exports.submit_new_status();
+ submit_new_status();
});
$("body").on("keypress", ".user_status_overlay .user_status", (event) => {
if (event.key === "Enter") {
event.preventDefault();
- exports.submit_new_status();
+ submit_new_status();
}
});
$("body").on("keyup", ".user_status_overlay input.user_status", () => {
- exports.update_button();
- exports.toggle_clear_message_button();
+ update_button();
+ toggle_clear_message_button();
});
$("#clear_status_message_button").on("click", () => {
- exports.clear_message();
- exports.update_button();
+ clear_message();
+ update_button();
});
-};
-
-window.user_status_ui = exports;
+}