Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
refactor: Make compose size related variables & functions more specific.
N-Shar-mab432b269ee59
diff --git a/web/src/compose.js b/web/src/compose.jsindex b303961be9c..7cc3d0bb78a 100644--- a/web/src/compose.js+++ b/web/src/compose.js@@ -126,7 +126,7 @@ export function clear_compose_box() {* will have already done this action before echoing the message* to avoid the compose box triggering "new message out of view"* notifications incorrectly. */- if (compose_ui.is_full_size()) {+ if (compose_ui.is_expanded()) {compose_ui.make_compose_box_original_size();}$("textarea#compose-textarea").val("").trigger("focus");diff --git a/web/src/compose_actions.ts b/web/src/compose_actions.tsindex 7be97ac0ed0..9d2b1418ae4 100644--- a/web/src/compose_actions.ts+++ b/web/src/compose_actions.ts@@ -136,7 +136,7 @@ function clear_box(): void {let autosize_callback_opts: ComposeActionsStartOpts;export function autosize_message_content(opts: ComposeActionsStartOpts): void {- if (!compose_ui.is_full_size()) {+ if (!compose_ui.is_expanded()) {autosize_callback_opts = opts;$("textarea#compose-textarea").off("autosize:resized")@@ -376,7 +376,7 @@ export function start(raw_opts: ComposeActionsStartOpts): void {export function cancel(): void {// As user closes the compose box, restore the compose box max height- if (compose_ui.is_full_size()) {+ if (compose_ui.is_expanded()) {compose_ui.make_compose_box_original_size();}diff --git a/web/src/compose_ui.ts b/web/src/compose_ui.tsindex 51640745c39..da36f1e2983 100644--- a/web/src/compose_ui.ts+++ b/web/src/compose_ui.ts@@ -62,6 +62,7 @@ export let shift_pressed = false; // true or falseexport let code_formatting_button_triggered = false; // true or falseexport let compose_textarea_typeahead: Typeahead<TypeaheadSuggestion> | undefined;let full_size_status = false; // true or false+let expanded_status = false; // true or falseexport function set_compose_textarea_typeahead(typeahead: Typeahead<TypeaheadSuggestion>): void {compose_textarea_typeahead = typeahead;@@ -71,8 +72,9 @@ export function set_code_formatting_button_triggered(value: boolean): void {code_formatting_button_triggered = value;}-// Some functions to handle the full size status explicitly-export function set_full_size(is_full: boolean): void {+// Some functions to handle the expanded status explicitly+export function set_expanded_status(is_expanded: boolean, is_full = is_expanded): void {+ expanded_status = is_expanded;full_size_status = is_full;// Show typeahead at bottom of textarea on compose full size.if (compose_textarea_typeahead) {@@ -80,6 +82,10 @@ export function set_full_size(is_full: boolean): void {}}+export function is_expanded(): boolean {+ return expanded_status;+}+export function is_full_size(): boolean {return full_size_status;}@@ -87,7 +93,7 @@ export function is_full_size(): boolean {export function autosize_textarea($textarea: JQuery<HTMLTextAreaElement>): void {// Since this supports both compose and file upload, one must pass// in the text area to autosize.- if (!is_full_size()) {+ if (!is_expanded()) {autosize.update($textarea);}}@@ -364,7 +370,7 @@ export function set_compose_box_top(set_top: boolean): void {}export function make_compose_box_full_size(): void {- set_full_size(true);+ set_expanded_status(true);// The autosize should be destroyed for the full size compose// box else it will interfere and shrink its size accordingly.@@ -380,7 +386,7 @@ export function make_compose_box_full_size(): void {}export function make_compose_box_original_size(): void {- set_full_size(false);+ set_expanded_status(false);$("#compose").removeClass("compose-fullscreen");diff --git a/web/src/echo.js b/web/src/echo.jsindex 3a21c1acaa4..ef6c7958a68 100644--- a/web/src/echo.js+++ b/web/src/echo.js@@ -240,14 +240,14 @@ export function try_deliver_locally(message_request, insert_new_messages) {}// Now that we've committed to delivering the message locally, we- // shrink the compose-box if it is in the full-screen state. This+ // shrink the compose-box if it is in an expanded state. This// would have happened anyway in clear_compose_box, however, we// need to this operation before inserting the local message into// the feed. Otherwise, the out-of-view notification will be// always triggered on the top of compose-box, regardless of// whether the message would be visible after shrinking compose,- // because compose occludes the whole screen.- if (compose_ui.is_full_size()) {+ // because compose occludes the whole screen in full size state.+ if (compose_ui.is_expanded()) {compose_ui.make_compose_box_original_size();}diff --git a/web/src/recent_view_ui.ts b/web/src/recent_view_ui.tsindex a5b7d42792c..80b485bce6d 100644--- a/web/src/recent_view_ui.ts+++ b/web/src/recent_view_ui.ts@@ -1198,14 +1198,14 @@ function recenter_focus_if_off_screen(): void {function is_scroll_position_for_render(): boolean {const scroll_position = window.scrollY;const window_height = window.innerHeight;- // We allocate `--max-unexpanded-compose-height` in empty space+ // We allocate `--max-unmaximized-compose-height` in empty space// below the last rendered row in recent view.//// We don't want user to see this empty space until there are no// new rows to render when the user is scrolling to the bottom of// the view. So, we render new rows when user has scrolled 2 / 3// of (the total scrollable height - the empty space).- const compose_max_height = $("html").css("--max-unexpanded-compose-height");+ const compose_max_height = $("html").css("--max-unmaximized-compose-height");assert(typeof compose_max_height === "string");const scroll_max = document.body.scrollHeight - Number.parseInt(compose_max_height, 10);return scroll_position + window_height >= (2 / 3) * scroll_max;diff --git a/web/src/resize.ts b/web/src/resize.tsindex dd6484ed295..49cbb60377d 100644--- a/web/src/resize.ts+++ b/web/src/resize.ts@@ -128,7 +128,7 @@ export function reset_compose_message_max_height(bottom_whitespace_height?: numbexport function resize_bottom_whitespace(): void {const bottom_whitespace_height = get_bottom_whitespace_height();- $("html").css("--max-unexpanded-compose-height", `${bottom_whitespace_height}px`);+ $("html").css("--max-unmaximized-compose-height", `${bottom_whitespace_height}px`);// The height of the compose box is tied to that of// bottom_whitespace, so update it if necessary.//@@ -203,7 +203,7 @@ function resize_navbar_alerts(): void {navbar_alerts_height + "px",);- // If the compose-box is in expanded state,+ // If the compose-box is in full sized state,// reset its height as well.if (compose_ui.is_full_size()) {compose_ui.set_compose_box_top(true);diff --git a/web/styles/app_variables.css b/web/styles/app_variables.cssindex 30d89c19cd0..7f57c6615da 100644--- a/web/styles/app_variables.css+++ b/web/styles/app_variables.css@@ -231,12 +231,12 @@--informational-overlay-max-width: 550px;/*- Maximum height of the compose box when it is not in expanded state. This+ Maximum height of the compose box when it is not in maximised state. Thisis equal to the height of `#bottom_whitespace`. We expect resize.ts toreplace it with its pixel calculation since even if `vh` has great support,it can change depending on browser / OS on mobile devices.*/- --max-unexpanded-compose-height: 40vh;+ --max-unmaximized-compose-height: 40vh;/*Line height of the message buttons in compose box. Here it's necessarydiff --git a/web/styles/inbox.css b/web/styles/inbox.cssindex cd168663a94..462e37f8baa 100644--- a/web/styles/inbox.css+++ b/web/styles/inbox.css@@ -147,7 +147,7 @@overflow: hidden;border-radius: 5px;border: 1px solid hsl(0deg 0% 0% / 20%);- margin-bottom: var(--max-unexpanded-compose-height);+ margin-bottom: var(--max-unmaximized-compose-height);/* margin(5) + search left padding(30) + search right padding (28) + border(2px) = 65px */max-width: calc(var(--width-inbox-search) + var(--width-inbox-filters-dropdown) +diff --git a/web/styles/recent_view.css b/web/styles/recent_view.cssindex 211b31cb3dc..a2db9dbf7f5 100644--- a/web/styles/recent_view.css+++ b/web/styles/recent_view.css@@ -31,7 +31,7 @@padding-top: var(--navbar-fixed-height);/* Add bottom padding equal to `#bottom-whitespace`. This helps us keep #compose visibleat its max-height without overlapping with any visible topics. */- padding-bottom: var(--max-unexpanded-compose-height);+ padding-bottom: var(--max-unmaximized-compose-height);& td {vertical-align: middle;diff --git a/web/styles/zulip.css b/web/styles/zulip.cssindex 071131fc3a8..93492e8b017 100644--- a/web/styles/zulip.css+++ b/web/styles/zulip.css@@ -1429,7 +1429,7 @@ nav {#bottom_whitespace {display: block;- height: var(--max-unexpanded-compose-height);+ height: var(--max-unmaximized-compose-height);}.operator_value {diff --git a/web/tests/compose_actions.test.js b/web/tests/compose_actions.test.jsindex dd8e3e5850a..28fced15d64 100644--- a/web/tests/compose_actions.test.js+++ b/web/tests/compose_actions.test.js@@ -29,7 +29,7 @@ const compose_pm_pill = mock_esm("../src/compose_pm_pill", {});const compose_ui = mock_esm("../src/compose_ui", {autosize_textarea: noop,- is_full_size: () => false,+ is_expanded: () => false,set_focus: noop,compute_placeholder_text: noop,});diff --git a/web/tests/compose_ui.test.js b/web/tests/compose_ui.test.jsindex 4f1d983d283..7c1b19feb99 100644--- a/web/tests/compose_ui.test.js+++ b/web/tests/compose_ui.test.js@@ -489,13 +489,13 @@ run_test("test_compose_height_changes", ({override, override_rewire}) => {compose_ui.make_compose_box_full_size();assert.ok($("#compose").hasClass("compose-fullscreen"));- assert.ok(compose_ui.is_full_size());+ assert.ok(compose_ui.is_expanded());assert.ok(autosize_destroyed);assert.ok(compose_box_top_set);compose_ui.make_compose_box_original_size();assert.ok(!$("#compose").hasClass("compose-fullscreen"));- assert.ok(!compose_ui.is_full_size());+ assert.ok(!compose_ui.is_expanded());assert.ok(!compose_box_top_set);});