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.
This commit is contained in:
Aman Agrawal 2023-05-30 01:03:06 +05:30 committed by Tim Abbott
parent 0f4bccd107
commit 7706d64530
1 changed files with 10 additions and 9 deletions

View File

@ -12,13 +12,15 @@ import * as navigate from "./navigate";
import * as popovers from "./popovers"; import * as popovers from "./popovers";
import * as util from "./util"; import * as util from "./util";
function get_bottom_whitespace_height() {
return message_viewport.height() * 0.4;
}
function get_new_heights() { function get_new_heights() {
const res = {}; const res = {};
const viewport_height = message_viewport.height(); const viewport_height = message_viewport.height();
const right_sidebar_shortcuts_height = $(".right-sidebar-shortcuts").safeOuterHeight(true) || 0; const right_sidebar_shortcuts_height = $(".right-sidebar-shortcuts").safeOuterHeight(true) || 0;
res.bottom_whitespace_height = viewport_height * 0.4;
res.stream_filters_max_height = res.stream_filters_max_height =
viewport_height - viewport_height -
Number.parseInt($("#left-sidebar").css("paddingTop"), 10) - 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. // Compute bottom_whitespace_height if not provided by caller.
if (bottom_whitespace_height === undefined) { if (bottom_whitespace_height === undefined) {
const h = get_new_heights(); bottom_whitespace_height = get_bottom_whitespace_height();
bottom_whitespace_height = h.bottom_whitespace_height;
} }
const compose_height = $("#compose").get(0).getBoundingClientRect().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) { export function resize_bottom_whitespace() {
$("#bottom_whitespace").height(h.bottom_whitespace_height); 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 // The height of the compose box is tied to that of
// bottom_whitespace, so update it if necessary. // 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 // height correctly while compose is hidden. This is OK, because
// we also resize compose every time it is opened. // we also resize compose every time it is opened.
if (compose_state.composing()) { 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() { export function resize_stream_filters_container() {
const h = get_new_heights(); const h = get_new_heights();
resize_bottom_whitespace(h); resize_bottom_whitespace();
$("#left_sidebar_scroll_container").css("max-height", h.stream_filters_max_height); $("#left_sidebar_scroll_container").css("max-height", h.stream_filters_max_height);
} }