From 7706d64530b466c2c4dcfebaff98d3990a8ebcb1 Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Tue, 30 May 2023 01:03:06 +0530 Subject: [PATCH] resize: Extract method to get bottom whitespace. Minor optimization to reduce left sidebar and right sidebar calculation when we just want to update bottom whitespace height. --- web/src/resize.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/web/src/resize.js b/web/src/resize.js index 2fe8562a5f..c7132b857d 100644 --- a/web/src/resize.js +++ b/web/src/resize.js @@ -12,13 +12,15 @@ import * as navigate from "./navigate"; import * as popovers from "./popovers"; import * as util from "./util"; +function get_bottom_whitespace_height() { + return message_viewport.height() * 0.4; +} + function get_new_heights() { const res = {}; const viewport_height = message_viewport.height(); const right_sidebar_shortcuts_height = $(".right-sidebar-shortcuts").safeOuterHeight(true) || 0; - res.bottom_whitespace_height = viewport_height * 0.4; - res.stream_filters_max_height = viewport_height - Number.parseInt($("#left-sidebar").css("paddingTop"), 10) - @@ -90,8 +92,7 @@ export function reset_compose_message_max_height(bottom_whitespace_height) { // Compute bottom_whitespace_height if not provided by caller. if (bottom_whitespace_height === undefined) { - const h = get_new_heights(); - bottom_whitespace_height = h.bottom_whitespace_height; + bottom_whitespace_height = get_bottom_whitespace_height(); } const compose_height = $("#compose").get(0).getBoundingClientRect().height; @@ -116,9 +117,9 @@ export function reset_compose_message_max_height(bottom_whitespace_height) { ); } -export function resize_bottom_whitespace(h) { - $("#bottom_whitespace").height(h.bottom_whitespace_height); - +export function resize_bottom_whitespace() { + const bottom_whitespace_height = get_bottom_whitespace_height(); + $("#bottom_whitespace").height(bottom_whitespace_height); // The height of the compose box is tied to that of // bottom_whitespace, so update it if necessary. // @@ -126,13 +127,13 @@ export function resize_bottom_whitespace(h) { // height correctly while compose is hidden. This is OK, because // we also resize compose every time it is opened. if (compose_state.composing()) { - reset_compose_message_max_height(h.bottom_whitespace_height); + reset_compose_message_max_height(bottom_whitespace_height); } } export function resize_stream_filters_container() { const h = get_new_heights(); - resize_bottom_whitespace(h); + resize_bottom_whitespace(); $("#left_sidebar_scroll_container").css("max-height", h.stream_filters_max_height); }