From aeab2fd0979b61bbd888e9d126ec2f9832f1c980 Mon Sep 17 00:00:00 2001 From: Evy Kassirer Date: Thu, 14 Aug 2025 15:21:00 -0700 Subject: [PATCH] stream_list_sort: Remove stream list row navigation code. This stopped being used after 78a3ef56e437a9d705b027813e3cffe54f2a93d1. --- web/src/stream_list_sort.ts | 122 ++-------------------------- web/tests/stream_list_sort.test.cjs | 10 --- 2 files changed, 7 insertions(+), 125 deletions(-) diff --git a/web/src/stream_list_sort.ts b/web/src/stream_list_sort.ts index b280deb9b6..60e3d0c250 100644 --- a/web/src/stream_list_sort.ts +++ b/web/src/stream_list_sort.ts @@ -13,18 +13,7 @@ import * as util from "./util.ts"; let first_render_completed = false; let current_sections: StreamListSection[] = []; - -export type StreamListRow = - | { - type: "stream"; - stream_id: number; - inactive_or_muted: boolean; - } - | { - type: "inactive_or_muted_toggle"; - section_id: string; - }; -let all_rows: StreamListRow[] = []; +let all_rows: number[] = []; // Because we need to check whether we are filtering inactive streams // in a loop over all streams to render the left sidebar, and the @@ -34,7 +23,7 @@ let all_rows: StreamListRow[] = []; let filter_out_inactives = false; export function get_stream_ids(): number[] { - return all_rows.flatMap((row) => (row.type === "stream" ? row.stream_id : [])); + return [...all_rows]; } export function section_ids(): string[] { @@ -260,29 +249,11 @@ export function sort_groups( if (!same_as_before) { first_render_completed = true; current_sections = new_sections; - all_rows = []; - for (const section of current_sections) { - for (const stream_id of section.streams) { - all_rows.push({ - type: "stream", - stream_id, - inactive_or_muted: false, - }); - } - for (const stream_id of [...section.muted_streams, ...section.inactive_streams]) { - all_rows.push({ - type: "stream", - stream_id, - inactive_or_muted: true, - }); - } - if (section.inactive_streams.length > 0 || section.muted_streams.length > 0) { - all_rows.push({ - type: "inactive_or_muted_toggle", - section_id: section.id, - }); - } - } + all_rows = current_sections.flatMap((section) => [ + ...section.streams, + ...section.muted_streams, + ...section.inactive_streams, + ]); } return { @@ -291,85 +262,6 @@ export function sort_groups( }; } -export function first_row(): StreamListRow | undefined { - return all_rows.at(0); -} - -function is_visible_row( - row: StreamListRow, - section_id_map: Map, - sections_showing_inactive_or_muted: Set, - collapsed_sections: Set, - active_stream_id: number | undefined, -): boolean { - if (row.type === "stream") { - const stream_id = row.stream_id; - assert(stream_id !== undefined); - const section = section_id_map.get(stream_id)!; - if (collapsed_sections.has(section.id) && active_stream_id !== stream_id) { - return false; - } - if (!sections_showing_inactive_or_muted.has(section.id) && row.inactive_or_muted) { - return false; - } - } else if (row.type === "inactive_or_muted_toggle" && collapsed_sections.has(row.section_id)) { - return false; - } - return true; -} - -export function prev_row( - row: StreamListRow, - sections_showing_inactive_or_muted: Set, - collapsed_sections: Set, - active_stream_id: number | undefined, -): StreamListRow | undefined { - let i = all_rows.indexOf(row); - const section_id_map = current_section_ids_for_streams(); - while (i > 0) { - i -= 1; - const prev_row = all_rows[i]!; - if ( - is_visible_row( - prev_row, - section_id_map, - sections_showing_inactive_or_muted, - collapsed_sections, - active_stream_id, - ) - ) { - return prev_row; - } - } - return undefined; -} - -export function next_row( - row: StreamListRow, - sections_showing_inactive_or_muted: Set, - collapsed_sections: Set, - active_stream_id: number | undefined, -): StreamListRow | undefined { - let i = all_rows.indexOf(row); - const section_id_map = current_section_ids_for_streams(); - while (i + 1 < all_rows.length) { - i += 1; - const next_row = all_rows[i]!; - if ( - is_visible_row( - next_row, - section_id_map, - sections_showing_inactive_or_muted, - collapsed_sections, - active_stream_id, - ) - ) { - return next_row; - } - } - return undefined; -} - export function initialize(): void { set_filter_out_inactives(); } diff --git a/web/tests/stream_list_sort.test.cjs b/web/tests/stream_list_sort.test.cjs index 349ab6a323..70761b3643 100644 --- a/web/tests/stream_list_sort.test.cjs +++ b/web/tests/stream_list_sort.test.cjs @@ -121,7 +121,6 @@ test("no_subscribed_streams", () => { ], same_as_before: sorted.same_as_before, }); - assert.equal(stream_list_sort.first_row(), undefined); }); test("basics", () => { @@ -150,15 +149,6 @@ test("basics", () => { ]); assert.deepEqual(normal.muted_streams, [muted_active.stream_id]); - // Test keyboard UI / cursor code (currently mostly deleted). - // TODO/channel-folders: Re-add keyboard navigation tests, - // including some with filtering. This mainly requires either - // exporting some parts of the stream_list module, or refactoring - // to move some of the stream_list data objects to another module. - const row = stream_list_sort.first_row(); - assert.equal(row.type, "stream"); - assert.equal(row.stream_id, scalene.stream_id); - // Test filtering sorted_sections = sort_groups("s").sections; assert.deepEqual(sorted_sections.length, 2);