topic_list: Fix duplicate topic rows in left sidebar.

When narrowing to an existing topic name with different casing, left
sidebar renders duplicate topic rows for the existing topic name and
one with the different casing. Since topic names are case insensitive,
it should narrow to the existing row only.

Fixes regression from #29175.
This commit is contained in:
Pratik Chanda 2024-06-25 16:06:09 +05:30 committed by Tim Abbott
parent d356577c29
commit d3fbfeae31
1 changed files with 6 additions and 1 deletions

View File

@ -140,6 +140,11 @@ function choose_topics(
}
}
function contains_topic(topic_names: string[], narrowed_topic: string): boolean {
const lower_cased_topics = topic_names.map((name) => name.toLowerCase());
return lower_cased_topics.includes(narrowed_topic.toLowerCase());
}
type TopicListInfo = {
items: TopicInfo[];
num_possible_topics: number;
@ -174,7 +179,7 @@ export function get_list_info(
if (
stream_id === narrow_state.stream_id() &&
narrowed_topic &&
!topic_names.includes(narrowed_topic)
!contains_topic(topic_names, narrowed_topic)
) {
topic_names.unshift(narrowed_topic);
}