From d7936fe576aca9bef893f87ae4055239efd20fd7 Mon Sep 17 00:00:00 2001 From: sujal shah Date: Wed, 8 May 2024 18:30:30 +0530 Subject: [PATCH] stream_overlay: Change the subscribed_only to show_subscribed. This commit changes the variable and function name from "subscribed_only" to "show_subscribed" and "set_subscribed_only" to "set_show_subscribed" so that in the next commit, when the "not subscribed" tab is added, we can use a similar variable named "show_unsubscribed" and function named "set_show_unsubscribed". --- web/src/stream_settings_ui.js | 12 ++++++------ web/src/stream_ui_updates.js | 8 ++++---- web/tests/stream_settings_ui.test.js | 26 +++++++++++++------------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/web/src/stream_settings_ui.js b/web/src/stream_settings_ui.js index adbb2e5f88..d033ec6a47 100644 --- a/web/src/stream_settings_ui.js +++ b/web/src/stream_settings_ui.js @@ -348,7 +348,7 @@ export function update_settings_for_unsubscribed(slim_sub) { } function triage_stream(left_panel_params, sub) { - if (left_panel_params.subscribed_only && !sub.subscribed) { + if (left_panel_params.show_subscribed && !sub.subscribed) { // reject non-subscribed streams return "rejected"; } @@ -443,7 +443,7 @@ export function update_empty_left_panel_message() { $(".no-streams-to-show").show(); } -// LeftPanelParams { input: String, subscribed_only: Boolean, sort_order: String } +// LeftPanelParams { input: String, show_subscribed: Boolean, sort_order: String } export function redraw_left_panel(left_panel_params = get_left_panel_params()) { // We only get left_panel_params passed in from tests. Real // code calls get_left_panel_params(). @@ -507,7 +507,7 @@ export function get_left_panel_params() { const input = $search_box.expectOne().val().trim(); const params = { input, - subscribed_only: stream_ui_updates.subscribed_only, + show_subscribed: stream_ui_updates.show_subscribed, sort_order, }; return params; @@ -524,9 +524,9 @@ export function switch_stream_tab(tab_name) { */ if (tab_name === "all-streams") { - stream_ui_updates.set_subscribed_only(false); + stream_ui_updates.set_show_subscribed(false); } else if (tab_name === "subscribed") { - stream_ui_updates.set_subscribed_only(true); + stream_ui_updates.set_show_subscribed(true); } redraw_left_panel(); @@ -597,7 +597,7 @@ export function setup_page(callback) { // Reset our internal state to reflect that we're initially in // the "Subscribed" tab if we're reopening "Stream settings". - stream_ui_updates.set_subscribed_only(true); + stream_ui_updates.set_show_subscribed(true); toggler = components.toggle({ child_wants_focus: true, values: [ diff --git a/web/src/stream_ui_updates.js b/web/src/stream_ui_updates.js index 3c7cea1816..e0f1bfb119 100644 --- a/web/src/stream_ui_updates.js +++ b/web/src/stream_ui_updates.js @@ -28,16 +28,16 @@ function settings_button_for_sub(sub) { ); } -export let subscribed_only = true; +export let show_subscribed = true; export function is_subscribed_stream_tab_active() { // Returns true if "Subscribed" tab in stream settings is open // otherwise false. - return subscribed_only; + return show_subscribed; } -export function set_subscribed_only(value) { - subscribed_only = value; +export function set_show_subscribed(value) { + show_subscribed = value; } export function update_web_public_stream_privacy_option_state($container) { diff --git a/web/tests/stream_settings_ui.test.js b/web/tests/stream_settings_ui.test.js index 494b95d46c..745b65fa1b 100644 --- a/web/tests/stream_settings_ui.test.js +++ b/web/tests/stream_settings_ui.test.js @@ -154,33 +154,33 @@ run_test("redraw_left_panel", ({mock_template}) => { } // Search with single keyword - test_filter({input: "Po", subscribed_only: false}, [poland, pomona]); + test_filter({input: "Po", show_subscribed: false}, [poland, pomona]); assert.ok(ui_called); // The denmark row is active, even though it's not displayed. assert.ok($denmark_row.hasClass("active")); // Search with multiple keywords - test_filter({input: "Denmark, Pol", subscribed_only: false}, [denmark, poland]); - test_filter({input: "Den, Pol", subscribed_only: false}, [denmark, poland]); + test_filter({input: "Denmark, Pol", show_subscribed: false}, [denmark, poland]); + test_filter({input: "Den, Pol", show_subscribed: false}, [denmark, poland]); // Search is case-insensitive - test_filter({input: "po", subscribed_only: false}, [poland, pomona]); + test_filter({input: "po", show_subscribed: false}, [poland, pomona]); // Search handles unusual characters like C++ - test_filter({input: "c++", subscribed_only: false}, [cpp]); + test_filter({input: "c++", show_subscribed: false}, [cpp]); // Search subscribed streams only - test_filter({input: "d", subscribed_only: true}, [poland]); + test_filter({input: "d", show_subscribed: true}, [poland]); // Search terms match stream description - test_filter({input: "Co", subscribed_only: false}, [denmark, pomona]); + test_filter({input: "Co", show_subscribed: false}, [denmark, pomona]); // Search names AND descriptions - test_filter({input: "Mon", subscribed_only: false}, [pomona, poland]); + test_filter({input: "Mon", show_subscribed: false}, [pomona, poland]); // Explicitly order streams by name - test_filter({input: "", subscribed_only: false, sort_order: "by-stream-name"}, [ + test_filter({input: "", show_subscribed: false, sort_order: "by-stream-name"}, [ cpp, denmark, poland, @@ -189,7 +189,7 @@ run_test("redraw_left_panel", ({mock_template}) => { ]); // Order streams by subscriber count - test_filter({input: "", subscribed_only: false, sort_order: "by-subscriber-count"}, [ + test_filter({input: "", show_subscribed: false, sort_order: "by-subscriber-count"}, [ poland, cpp, zzyzx, @@ -198,7 +198,7 @@ run_test("redraw_left_panel", ({mock_template}) => { ]); // Order streams by weekly traffic - test_filter({input: "", subscribed_only: false, sort_order: "by-weekly-traffic"}, [ + test_filter({input: "", show_subscribed: false, sort_order: "by-weekly-traffic"}, [ poland, cpp, zzyzx, @@ -207,7 +207,7 @@ run_test("redraw_left_panel", ({mock_template}) => { ]); // Sort for subscribed only. - test_filter({input: "", subscribed_only: true, sort_order: "by-subscriber-count"}, [ + test_filter({input: "", show_subscribed: true, sort_order: "by-subscriber-count"}, [ poland, cpp, zzyzx, @@ -225,7 +225,7 @@ run_test("redraw_left_panel", ({mock_template}) => { $(".stream-row-denmark").removeClass("active"); }; - test_filter({input: "d", subscribed_only: true}, [poland]); + test_filter({input: "d", show_subscribed: true}, [poland]); assert.ok($(".stream-row-denmark").hasClass("active")); stream_settings_ui.switch_stream_tab("subscribed");