Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
recent_topics: Re-select last selected topic.
Aman Agrawalcfbed9a60c3b
diff --git a/static/js/click_handlers.js b/static/js/click_handlers.jsindex 94ac78fbd09..096ff5df77b 100644--- a/static/js/click_handlers.js+++ b/static/js/click_handlers.js@@ -433,9 +433,16 @@ export function initialize() {$("body").on("click", "td.recent_topic_name", (e) => {e.stopPropagation();+ // The element's parent may re-render while it is being passed to+ // other functions, so, we get topic_key first.const topic_row = $(e.target).closest("tr");+ const topic_key = topic_row.attr("id").slice("recent_topics:".length - 1);const topic_row_index = topic_row.index();- recent_topics_ui.focus_clicked_element(topic_row_index, recent_topics_ui.COLUMNS.topic);+ recent_topics_ui.focus_clicked_element(+ topic_row_index,+ recent_topics_ui.COLUMNS.topic,+ topic_key,+ );window.location.href = $(e.currentTarget).find("a").attr("href");});diff --git a/static/js/recent_topics_ui.js b/static/js/recent_topics_ui.jsindex 0ff19bd5e92..ff88e848552 100644--- a/static/js/recent_topics_ui.js+++ b/static/js/recent_topics_ui.js@@ -47,6 +47,10 @@ const MAX_EXTRA_SENDERS = 10;// `row_focus` and `col_focus`.export let current_focus_elem = "table";+// If user clicks a topic in recent topics, then+// we store that topic here so that we can restore focus+// to that topic when user revisits.+let last_visited_topic = "";let row_focus = 0;// Start focus on the topic column, so Down+Enter works to visit a topic.let col_focus = 1;@@ -176,6 +180,18 @@ export function revive_current_focus() {}if (is_table_focused()) {+ if (last_visited_topic) {+ const topic_last_msg_id = topics.get(last_visited_topic).last_msg_id;+ const current_list = topics_widget.get_current_list();+ const last_visited_topic_index = current_list.findIndex(+ (topic) => topic.last_msg_id === topic_last_msg_id,+ );+ if (last_visited_topic_index >= 0) {+ row_focus = last_visited_topic_index;+ }+ last_visited_topic = "";+ }+set_table_focus(row_focus, col_focus);return true;}@@ -655,10 +671,14 @@ function is_focus_at_last_table_row() {return row_focus === topic_rows.length - 1;}-export function focus_clicked_element(topic_row_index, col) {+export function focus_clicked_element(topic_row_index, col, topic_key) {current_focus_elem = "table";col_focus = col;row_focus = topic_row_index;++ if (col === COLUMNS.topic) {+ last_visited_topic = topic_key;+ }// Set compose_closed_ui reply button text. The rest of the table// focus logic should be a noop.set_table_focus(row_focus, col_focus);