From 7f26905fe0881f1908f38e267c5bde2c1b515cd9 Mon Sep 17 00:00:00 2001 From: Sayam Samal Date: Wed, 13 Dec 2023 09:15:44 +0530 Subject: [PATCH] compose_actions: Hide compose box when navigating to inbox/recent view. Currently, given that the compose box is already open, it stays open when the user navigates to the inbox/recent view, even when there is no modifications to the message or recipients. This commit adds conditions to close the compose box when navigating to the inbox/recent view, except when we can reasonably infer that it was the intended action. --- web/src/compose_actions.js | 18 ++++++++++++++++++ web/src/views_util.js | 2 ++ 2 files changed, 20 insertions(+) diff --git a/web/src/compose_actions.js b/web/src/compose_actions.js index c54b11757d..986875e0ab 100644 --- a/web/src/compose_actions.js +++ b/web/src/compose_actions.js @@ -336,6 +336,24 @@ export function cancel() { $(document).trigger("compose_canceled.zulip"); } +export function on_show_navigation_view() { + /* This function dictates the behavior of the compose box + * when navigating to a view, as opposed to a narrow. */ + + // Leave the compose box closed if it was already closed. + if (!compose_state.composing()) { + return; + } + + // Leave the compose box open if there is content or if the recipient was edited. + if (compose_state.has_message_content() || compose_state.is_recipient_edited_manually()) { + return; + } + + // Otherwise, close the compose box. + cancel(); +} + export function on_topic_narrow() { if (!compose_state.composing()) { // If our compose box is closed, then just diff --git a/web/src/views_util.js b/web/src/views_util.js index fa3af6581d..301ac1f910 100644 --- a/web/src/views_util.js +++ b/web/src/views_util.js @@ -1,5 +1,6 @@ import $ from "jquery"; +import * as compose_actions from "./compose_actions"; import * as compose_recipient from "./compose_recipient"; import * as dropdown_widget from "./dropdown_widget"; import {$t} from "./i18n"; @@ -87,6 +88,7 @@ export function show(opts) { compose_recipient.handle_middle_pane_transition(); search.clear_search_form(); opts.complete_rerender(); + compose_actions.on_show_navigation_view(); // Misc. if (opts.is_recent_view) {