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

Anders Kaseorg2771434aad50
diff --git a/.eslintrc.json b/.eslintrc.json
index 1040c8fa49a..380533a79a0 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -272,7 +272,6 @@
"stream_list": false,
"stream_muting": false,
"stream_popover": false,
- "stream_sort": false,
"stream_ui_updates": false,
"StripeCheckout": false,
"submessage": false,
diff --git a/frontend_tests/node_tests/general.js b/frontend_tests/node_tests/general.js
index 4766fedd3ce..c58ced59180 100644
--- a/frontend_tests/node_tests/general.js
+++ b/frontend_tests/node_tests/general.js
@@ -608,7 +608,6 @@ run_test("unread_ops", () => {
const topic_list = set_global("topic_list", {});
-zrequire("stream_sort");
const stream_list = zrequire("stream_list");
const social_stream = {
diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.js
index 59a32b045d3..6237eaf8cbb 100644
--- a/frontend_tests/node_tests/ui_init.js
+++ b/frontend_tests/node_tests/ui_init.js
@@ -117,7 +117,6 @@ rewiremock.proxy(() => zrequire("notifications"), {
zrequire("pm_list");
zrequire("list_cursor");
zrequire("keydown_util");
-zrequire("stream_sort");
zrequire("stream_list");
zrequire("topic_list");
zrequire("topic_zoom");
diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js
index 8cafb151ac9..c970c8284dd 100644
--- a/static/js/bundles/app.js
+++ b/static/js/bundles/app.js
@@ -39,7 +39,6 @@ import "../topic_list";
import "../pm_list_dom";
import "../pm_list";
import "../recent_senders";
-import "../stream_sort";
import "../topic_generator";
import "../top_left_corner";
import "../stream_list";
diff --git a/static/js/global.d.ts b/static/js/global.d.ts
index 7700a8b2868..92eea642ff5 100644
--- a/static/js/global.d.ts
+++ b/static/js/global.d.ts
@@ -138,7 +138,6 @@ declare let stream_events: any;
declare let stream_list: any;
declare let stream_muting: any;
declare let stream_popover: any;
-declare let stream_sort: any;
declare let stream_ui_updates: any;
declare let submessage: any;
declare let subs: any;
diff --git a/static/js/stream_list.js b/static/js/stream_list.js
index 43c6303d6b0..4703c40bf6f 100644
--- a/static/js/stream_list.js
+++ b/static/js/stream_list.js
@@ -5,6 +5,8 @@ const _ = require("lodash");
const render_stream_privacy = require("../templates/stream_privacy.hbs");
const render_stream_sidebar_row = require("../templates/stream_sidebar_row.hbs");
+const stream_sort = require("./stream_sort");
+
let has_scrolled = false;
exports.update_count_in_dom = function (unread_count_elem, count) {
diff --git a/static/js/stream_sort.js b/static/js/stream_sort.js
index df84c838afa..4ffe912f42e 100644
--- a/static/js/stream_sort.js
+++ b/static/js/stream_sort.js
@@ -1,20 +1,18 @@
-"use strict";
-
-const util = require("./util");
+import * as util from "./util";
let previous_pinned;
let previous_normal;
let previous_dormant;
let all_streams = [];
-exports.get_streams = function () {
+export function get_streams() {
// Right now this is only used for testing, but we should
// use it for things like hotkeys that cycle through streams.
const sorted_streams = all_streams.map((stream_id) =>
stream_data.maybe_get_stream_name(stream_id),
);
return sorted_streams;
-};
+}
function compare_function(a, b) {
const stream_a = stream_data.get_sub_by_id(a);
@@ -46,7 +44,7 @@ function filter_streams_by_search(streams, search_term) {
return filtered_streams;
}
-exports.sort_groups = function (streams, search_term) {
+export function sort_groups(streams, search_term) {
if (streams.length === 0) {
return undefined;
}
@@ -97,7 +95,7 @@ exports.sort_groups = function (streams, search_term) {
normal_streams,
dormant_streams,
};
-};
+}
function maybe_get_stream_id(i) {
if (i < 0 || i >= all_streams.length) {
@@ -107,11 +105,11 @@ function maybe_get_stream_id(i) {
return all_streams[i];
}
-exports.first_stream_id = function () {
+export function first_stream_id() {
return maybe_get_stream_id(0);
-};
+}
-exports.prev_stream_id = function (stream_id) {
+export function prev_stream_id(stream_id) {
const i = all_streams.indexOf(stream_id);
if (i < 0) {
@@ -119,9 +117,9 @@ exports.prev_stream_id = function (stream_id) {
}
return maybe_get_stream_id(i - 1);
-};
+}
-exports.next_stream_id = function (stream_id) {
+export function next_stream_id(stream_id) {
const i = all_streams.indexOf(stream_id);
if (i < 0) {
@@ -129,6 +127,4 @@ exports.next_stream_id = function (stream_id) {
}
return maybe_get_stream_id(i + 1);
-};
-
-window.stream_sort = exports;
+}
diff --git a/static/js/topic_generator.js b/static/js/topic_generator.js
index 6e7e18ebd65..b34c2d850e7 100644
--- a/static/js/topic_generator.js
+++ b/static/js/topic_generator.js
@@ -1,6 +1,7 @@
"use strict";
const pm_conversations = require("./pm_conversations");
+const stream_sort = require("./stream_sort");
exports.next_topic = function (streams, get_topics, has_unread_messages, curr_stream, curr_topic) {
const curr_stream_index = streams.indexOf(curr_stream); // -1 if not found