refactor: Initialise state variables to undefined instead of false.

For compose state variables `last_focused_compose_type_input` and
`message_type` that are assigned non-boolean values on user interaction,
`undefined` is the semantically better choice than `false` for
initialisation, to avoid incorrect boolean implications.
This commit is contained in:
N-Shar-ma 2024-01-08 03:58:42 +05:30 committed by Tim Abbott
parent 89f9e097db
commit 2952f0f44f
6 changed files with 12 additions and 12 deletions

View File

@ -332,7 +332,7 @@ export function cancel() {
clear_box();
compose_banner.clear_message_sent_banners();
call_hooks(compose_cancel_hooks);
compose_state.set_message_type(false);
compose_state.set_message_type(undefined);
compose_pm_pill.clear();
$(document).trigger("compose_canceled.zulip");
}

View File

@ -5,9 +5,9 @@ import {$t} from "./i18n";
import * as people from "./people";
import * as sub_store from "./sub_store";
let message_type: "stream" | "private" | false = false;
let message_type: "stream" | "private" | undefined;
let recipient_edited_manually = false;
let last_focused_compose_type_input: HTMLInputElement | false = false; // an HTML input element or false-y
let last_focused_compose_type_input: HTMLInputElement | undefined;
// We use this variable to keep track of whether user has viewed the topic resolved
// banner for the current compose session, for a narrow. This prevents the banner
@ -29,15 +29,15 @@ export function set_last_focused_compose_type_input(element: HTMLInputElement):
last_focused_compose_type_input = element;
}
export function get_last_focused_compose_type_input(): HTMLInputElement | false {
export function get_last_focused_compose_type_input(): HTMLInputElement | undefined {
return last_focused_compose_type_input;
}
export function set_message_type(msg_type: "stream" | "private" | false): void {
export function set_message_type(msg_type: "stream" | "private" | undefined): void {
message_type = msg_type;
}
export function get_message_type(): "stream" | "private" | false {
export function get_message_type(): "stream" | "private" | undefined {
return message_type;
}

View File

@ -564,7 +564,7 @@ test_ui("update_fade", ({override, override_rewire}) => {
update_narrow_to_recipient_visibility_called = true;
});
compose_state.set_message_type(false);
compose_state.set_message_type(undefined);
compose_recipient.update_on_recipient_change();
assert.ok(!set_focused_recipient_checked);
assert.ok(!update_all_called);

View File

@ -100,14 +100,14 @@ function test(label, f) {
$(".new_message_textarea").css = noop;
people.init();
compose_state.set_message_type(false);
compose_state.set_message_type(undefined);
f(helpers);
});
}
test("initial_state", () => {
assert.equal(compose_state.composing(), false);
assert.equal(compose_state.get_message_type(), false);
assert.equal(compose_state.get_message_type(), undefined);
assert.equal(compose_state.has_message_content(), false);
});
@ -466,7 +466,7 @@ test("focus_in_empty_compose", () => {
$("textarea#compose-textarea").val("");
assert.ok(compose_state.focus_in_empty_compose());
compose_state.set_message_type(false);
compose_state.set_message_type(undefined);
assert.ok(!compose_state.focus_in_empty_compose());
$("textarea#compose-textarea").val("foo");

View File

@ -244,7 +244,7 @@ test("remove_old_drafts", () => {
});
test("update_draft", ({override, override_rewire}) => {
compose_state.set_message_type(false);
compose_state.set_message_type(undefined);
let draft_id = drafts.update_draft();
assert.equal(draft_id, undefined);

View File

@ -660,7 +660,7 @@ run_test("narrow_to_compose_target errors", ({disallow_rewire}) => {
disallow_rewire(narrow, "activate");
// No-op when not composing.
compose_state.set_message_type(false);
compose_state.set_message_type(undefined);
narrow.to_compose_target();
// No-op when empty stream.