mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
stream_list_sort: Remove stream list row navigation code.
This stopped being used after 78a3ef56e4.
This commit is contained in:
@@ -13,18 +13,7 @@ import * as util from "./util.ts";
|
|||||||
|
|
||||||
let first_render_completed = false;
|
let first_render_completed = false;
|
||||||
let current_sections: StreamListSection[] = [];
|
let current_sections: StreamListSection[] = [];
|
||||||
|
let all_rows: number[] = [];
|
||||||
export type StreamListRow =
|
|
||||||
| {
|
|
||||||
type: "stream";
|
|
||||||
stream_id: number;
|
|
||||||
inactive_or_muted: boolean;
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
type: "inactive_or_muted_toggle";
|
|
||||||
section_id: string;
|
|
||||||
};
|
|
||||||
let all_rows: StreamListRow[] = [];
|
|
||||||
|
|
||||||
// Because we need to check whether we are filtering inactive streams
|
// Because we need to check whether we are filtering inactive streams
|
||||||
// in a loop over all streams to render the left sidebar, and the
|
// 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;
|
let filter_out_inactives = false;
|
||||||
|
|
||||||
export function get_stream_ids(): number[] {
|
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[] {
|
export function section_ids(): string[] {
|
||||||
@@ -260,29 +249,11 @@ export function sort_groups(
|
|||||||
if (!same_as_before) {
|
if (!same_as_before) {
|
||||||
first_render_completed = true;
|
first_render_completed = true;
|
||||||
current_sections = new_sections;
|
current_sections = new_sections;
|
||||||
all_rows = [];
|
all_rows = current_sections.flatMap((section) => [
|
||||||
for (const section of current_sections) {
|
...section.streams,
|
||||||
for (const stream_id of section.streams) {
|
...section.muted_streams,
|
||||||
all_rows.push({
|
...section.inactive_streams,
|
||||||
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,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
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<number, StreamListSection>,
|
|
||||||
sections_showing_inactive_or_muted: Set<string>,
|
|
||||||
collapsed_sections: Set<string>,
|
|
||||||
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<string>,
|
|
||||||
collapsed_sections: Set<string>,
|
|
||||||
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<string>,
|
|
||||||
collapsed_sections: Set<string>,
|
|
||||||
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 {
|
export function initialize(): void {
|
||||||
set_filter_out_inactives();
|
set_filter_out_inactives();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,7 +121,6 @@ test("no_subscribed_streams", () => {
|
|||||||
],
|
],
|
||||||
same_as_before: sorted.same_as_before,
|
same_as_before: sorted.same_as_before,
|
||||||
});
|
});
|
||||||
assert.equal(stream_list_sort.first_row(), undefined);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("basics", () => {
|
test("basics", () => {
|
||||||
@@ -150,15 +149,6 @@ test("basics", () => {
|
|||||||
]);
|
]);
|
||||||
assert.deepEqual(normal.muted_streams, [muted_active.stream_id]);
|
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
|
// Test filtering
|
||||||
sorted_sections = sort_groups("s").sections;
|
sorted_sections = sort_groups("s").sections;
|
||||||
assert.deepEqual(sorted_sections.length, 2);
|
assert.deepEqual(sorted_sections.length, 2);
|
||||||
|
|||||||
Reference in New Issue
Block a user