Skip to content

Commit

Permalink
stream_settings: Fix stream row switching behavior.
Browse files Browse the repository at this point in the history
Add a rule to the switch_rows(event) function to avoid
switching stream row when pressing up/down key by checking
the current URL hash and the add_subscribers_pill focus state.
Add a utility function to hash_parser to help implement new
switch_rows behavior mentioned above.

Fixes #29690
  • Loading branch information
PieterCK committed Apr 25, 2024
1 parent 2ccbb9b commit 53ebe5b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions web/src/hash_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ export function is_create_new_stream_narrow(): boolean {
return window.location.hash === "#streams/new";
}

// this checks whether the use is in the stream settings and in the
// 'Subscribers' tab on the right panel of stream settings
export function is_editing_stream_subscribers(): boolean {
const hash_components = window.location.hash.slice(1).split(/\//);
console.log("hash_components", hash_components);
if (hash_components[0] !== "streams") {
return false;
}
if (!hash_components[3]) {
return false;
}
return hash_components[3] === "subscribers"
}

export const allowed_web_public_narrows = [
"channels",
"channel",
Expand Down
8 changes: 8 additions & 0 deletions web/src/stream_settings_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ export function setup_page(callback) {
// streams, either explicitly via user_can_create_streams, or
// implicitly because realm.realm_is_zephyr_mirror_realm.
$("#stream_filter input[type='text']").on("keypress", (e) => {
console.log("keypress", e);
if (!keydown_util.is_enter_event(e)) {
return;
}
Expand Down Expand Up @@ -727,6 +728,7 @@ export function switch_to_stream_row(stream_id) {
}

function show_right_section() {
console.log("SHOWING RIHGT SECTIOn")
$(".right").addClass("show");
$(".subscriptions-header").addClass("slide-left");
resize.resize_stream_subscribers_list();
Expand Down Expand Up @@ -796,10 +798,16 @@ export function launch(section, left_side_tab, right_side_tab) {

export function switch_rows(event) {
const active_data = stream_settings_components.get_active_data();
// console.log("div input clicked: ", $("#input").is(":change"))
let $add_subscriber_pill = $(".add_subscribers_container > div > .input");
let $switch_row;

if (hash_parser.is_create_new_stream_narrow()) {
// Prevent switching stream rows when creating a new stream
return false;
} else if (hash_parser.is_editing_stream_subscribers && $add_subscriber_pill.is(":focus")) {
// Prevent switching stream rows when adding a subscriber
return false;
} else if (!active_data.id || active_data.$row.hasClass("notdisplayed")) {
$switch_row = $("div.stream-row:not(.notdisplayed)").first();
if ($("#search_stream_name").is(":focus")) {
Expand Down

0 comments on commit 53ebe5b

Please sign in to comment.