From f95443ac8fb6addafd15ac29c42e9d8113129ccb Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Mon, 15 Mar 2021 09:31:31 +0000 Subject: [PATCH] recent_topics: Use is_visible for testing if RT is rendered. We don't want to rely on browser hash to check if RT is visible because soon we want to display default_view without any hash and RT may or may not be visible in that hash. --- frontend_tests/node_tests/recent_topics.js | 3 +++ static/js/hashchange.js | 4 ---- static/js/hotkey.js | 8 +++++--- static/js/recent_topics.js | 3 +-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/frontend_tests/node_tests/recent_topics.js b/frontend_tests/node_tests/recent_topics.js index a315a9c4a3..a5a4b97dac 100644 --- a/frontend_tests/node_tests/recent_topics.js +++ b/frontend_tests/node_tests/recent_topics.js @@ -93,6 +93,9 @@ mock_esm("../../static/js/muting", { mock_esm("../../static/js/narrow", { set_narrow_title: noop, }); +mock_esm("../../static/js/popovers", { + any_active: () => false, +}); mock_esm("../../static/js/recent_senders", { get_topic_recent_senders: () => [1, 2], }); diff --git a/static/js/hashchange.js b/static/js/hashchange.js index eb7b555277..23338b09e0 100644 --- a/static/js/hashchange.js +++ b/static/js/hashchange.js @@ -65,10 +65,6 @@ function maybe_hide_recent_topics() { return false; } -export function in_recent_topics_hash() { - return ["#recent_topics"].includes(window.location.hash); -} - export function changehash(newhash) { if (browser_history.state.changing_hash) { return; diff --git a/static/js/hotkey.js b/static/js/hotkey.js index af8079ddde..e8b3afbce7 100644 --- a/static/js/hotkey.js +++ b/static/js/hotkey.js @@ -222,11 +222,13 @@ export function in_content_editable_widget(e) { // Returns true if we handled it, false if the browser should. export function process_escape_key(e) { if ( - hashchange.in_recent_topics_hash() && + recent_topics.is_in_focus() && + // This will return false if `e.target` is not + // any of the recent topics elements by design. recent_topics.change_focused_element($(e.target), "escape") ) { - // Recent topics uses escape to make focus from RT search / filters to topics table. - // If focus already in table it returns false. + // Recent topics uses escape to switch focus from RT search / filters to topics table. + // If focus is already on the table it returns false. return true; } diff --git a/static/js/recent_topics.js b/static/js/recent_topics.js index a5d84e492a..f380b546b0 100644 --- a/static/js/recent_topics.js +++ b/static/js/recent_topics.js @@ -8,7 +8,6 @@ import * as compose from "./compose"; import * as compose_closed_ui from "./compose_closed_ui"; import * as compose_state from "./compose_state"; import * as hash_util from "./hash_util"; -import * as hashchange from "./hashchange"; import * as ListWidget from "./list_widget"; import {localstorage} from "./localstorage"; import * as message_store from "./message_store"; @@ -75,7 +74,7 @@ export function is_in_focus() { // Check if user is focused on // recent topics. return ( - hashchange.in_recent_topics_hash() && + is_visible() && !compose_state.composing() && !popovers.any_active() && !overlays.is_active() &&