refactor: Use confirm_dialog for unstar-all-messages.

This replaces the separate modal shown on clicking
"Unstar all messages" from the left sidebar to use
the confirm_dialog widget instead.
This commit is contained in:
Abhijeet Prasad Bodas
2021-03-08 13:24:37 +05:30
committed by Tim Abbott
parent eb7b699ac9
commit f17a52b2f3
5 changed files with 26 additions and 24 deletions

View File

@@ -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,
});
}

View File

@@ -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