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.

refactor: Use confirm_dialog for unstar-all-messages.

Abhijeet Prasad Bodasf17a52b2f367
diff --git a/static/js/starred_messages.js b/static/js/starred_messages.js
index 2806bd174d0..b1fe5c73403 100644
--- a/static/js/starred_messages.js
+++ b/static/js/starred_messages.js
@@ -1,3 +1,9 @@
+import $ from "jquery";
+
+import render_confirm_unstar_all_messages from "../templates/confirm_unstar_all_messages.hbs";
+
+import * as confirm_dialog from "./confirm_dialog";
+import * as message_flags from "./message_flags";
import * as stream_popover from "./stream_popover";
import * as top_left_corner from "./top_left_corner";
@@ -48,3 +54,16 @@ export function rerender_ui() {
top_left_corner.update_starred_count(count);
stream_popover.hide_starred_messages_popover();
}
+
+export function confirm_unstar_all_messages() {
+ const modal_parent = $(".left-sidebar-modal-holder");
+ const html_body = render_confirm_unstar_all_messages();
+
+ confirm_dialog.launch({
+ parent: modal_parent,
+ html_heading: i18n.t("Unstar all messages"),
+ html_body,
+ html_yes_button: i18n.t("Unstar messages"),
+ on_click: message_flags.unstar_all_messages,
+ });
+}
diff --git a/static/js/stream_popover.js b/static/js/stream_popover.js
index 934cf0817c1..9af6890b4f5 100644
--- a/static/js/stream_popover.js
+++ b/static/js/stream_popover.js
@@ -6,14 +6,12 @@ import render_move_topic_to_stream from "../templates/move_topic_to_stream.hbs";
import render_starred_messages_sidebar_actions from "../templates/starred_messages_sidebar_actions.hbs";
import render_stream_sidebar_actions from "../templates/stream_sidebar_actions.hbs";
import render_topic_sidebar_actions from "../templates/topic_sidebar_actions.hbs";
-import render_unstar_messages_modal from "../templates/unstar_messages_modal.hbs";
import * as blueslip from "./blueslip";
import * as browser_history from "./browser_history";
import * as channel from "./channel";
import * as hash_util from "./hash_util";
import * as message_edit from "./message_edit";
-import * as message_flags from "./message_flags";
import * as muting from "./muting";
import * as muting_ui from "./muting_ui";
import * as narrow from "./narrow";
@@ -431,15 +429,7 @@ export function register_stream_handlers() {
hide_starred_messages_popover();
e.preventDefault();
e.stopPropagation();
- $(".left-sidebar-modal-holder").empty();
- $(".left-sidebar-modal-holder").html(render_unstar_messages_modal());
- $("#unstar-messages-modal").modal("show");
- });
-
- $("body").on("click", "#do_unstar_messages_button", (e) => {
- $("#unstar-messages-modal").modal("hide");
- message_flags.unstar_all_messages();
- e.stopPropagation();
+ starred_messages.confirm_unstar_all_messages();
});
// Toggle displaying starred message count
diff --git a/static/templates/confirm_unstar_all_messages.hbs b/static/templates/confirm_unstar_all_messages.hbs
new file mode 100644
index 00000000000..3dacce78bcc
--- /dev/null
+++ b/static/templates/confirm_unstar_all_messages.hbs
@@ -0,0 +1,5 @@
+<p>
+ {{#tr this}}
+ Would you like to unstar all starred messages? This action cannot be undone.
+ {{/tr}}
+</p>
diff --git a/static/templates/unstar_messages_modal.hbs b/static/templates/unstar_messages_modal.hbs
deleted file mode 100644
index 2ae945ded93..00000000000
--- a/static/templates/unstar_messages_modal.hbs
+++ /dev/null
@@ -1,13 +0,0 @@
-<div id="unstar-messages-modal" class="modal new-style modal-bg hide fade" tabindex="-1" role="dialog" aria-labelledby="unstar_messages_modal_label" aria-hidden="true">
- <div class="modal-header">
- <button type="button" class="close" data-dismiss="modal" aria-label="{{t 'Close' }}"><span aria-hidden="true">&times;</span></button>
- <h3 id="unstar_messages_modal_label">{{t "Unstar all messages" }}</h3>
- </div>
- <div class="modal-body">
- <p>{{t "Would you like to unstar all starred messages? This action cannot be undone." }}</p>
- </div>
- <div class="modal-footer">
- <button type="button" class="button rounded" data-dismiss="modal">{{t "Cancel" }}</button>
- <button type="button" class="button rounded btn-danger" id="do_unstar_messages_button">{{t "Unstar all messages" }}</button>
- </div>
-</div>
diff --git a/tools/test-js-with-node b/tools/test-js-with-node
index c5c4c7da7d4..a8cef59223b 100755
--- a/tools/test-js-with-node
+++ b/tools/test-js-with-node
@@ -132,6 +132,7 @@ EXEMPT_FILES = {
"static/js/settings_users.js",
"static/js/setup.js",
"static/js/spoilers.js",
+ "static/js/starred_messages.js",
"static/js/stream_bar.js",
"static/js/stream_color.js",
"static/js/stream_create.js",