settings_components: Fix types in save_discard_stream_settings_widget_status_handler.

This had been getting undefined `sub` already, in the modal to create
a new channel, but managed to not cause errors because
`properties_elements` was empty and `button_state` didn't equal
`"unsaved"`, leaving areas that treated `sub` as defined not accessible.
This commit fixes the type and handles the `undefined` case more directly.
This commit is contained in:
evykassirer 2024-11-03 16:16:22 -08:00 committed by Tim Abbott
parent e50a51a8e1
commit 527d4672f8
1 changed files with 8 additions and 4 deletions

View File

@ -1203,14 +1203,17 @@ export function save_discard_realm_settings_widget_status_handler($subsection: J
export function save_discard_stream_settings_widget_status_handler( export function save_discard_stream_settings_widget_status_handler(
$subsection: JQuery, $subsection: JQuery,
sub: StreamSubscription, sub: StreamSubscription | undefined,
): void { ): void {
$subsection.find(".subsection-failed-status p").hide(); $subsection.find(".subsection-failed-status p").hide();
$subsection.find(".save-button").show(); $subsection.find(".save-button").show();
const properties_elements = get_subsection_property_elements($subsection); const properties_elements = get_subsection_property_elements($subsection);
const show_change_process_button = properties_elements.some((elem) => let show_change_process_button = false;
if (sub !== undefined) {
show_change_process_button = properties_elements.some((elem) =>
check_stream_settings_property_changed(elem, sub), check_stream_settings_property_changed(elem, sub),
); );
}
const $save_btn_controls = $subsection.find(".subsection-header .save-button-controls"); const $save_btn_controls = $subsection.find(".subsection-header .save-button-controls");
const button_state = show_change_process_button ? "unsaved" : "discarded"; const button_state = show_change_process_button ? "unsaved" : "discarded";
@ -1222,6 +1225,7 @@ export function save_discard_stream_settings_widget_status_handler(
// making it private unless they subscribe. // making it private unless they subscribe.
if ( if (
button_state === "unsaved" && button_state === "unsaved" &&
sub &&
!sub.invite_only && !sub.invite_only &&
!sub.subscribed && !sub.subscribed &&
switching_to_private(properties_elements) switching_to_private(properties_elements)