hashchange: Never set empty hash # in URL.

Setting empty hash `#` scrolls user to the top of message feed if
done via `window.location.hash` or using browser back / forward button.

To avoid this, we set don't set `hash` after org URL for default view
when user uses `escape` key or clicks on org logo.

In other situations, we explicitly set the hash of the view.
This commit is contained in:
Aman Agrawal
2023-05-26 02:00:20 +05:30
committed by Tim Abbott
parent 2f196bff19
commit 61f7ede43c
8 changed files with 59 additions and 9 deletions

View File

@@ -6,6 +6,7 @@ import * as alert_words_ui from "./alert_words_ui";
import * as attachments_ui from "./attachments_ui";
import * as blueslip from "./blueslip";
import * as bot_data from "./bot_data";
import * as browser_history from "./browser_history";
import {buddy_list} from "./buddy_list";
import * as compose from "./compose";
import * as compose_fade from "./compose_fade";
@@ -677,6 +678,7 @@ export function dispatch_normal_event(event) {
"send_read_receipts",
];
const original_default_view = user_settings.default_view;
if (user_display_settings.includes(event.property)) {
user_settings[event.property] = event.value;
}
@@ -689,6 +691,20 @@ export function dispatch_normal_event(event) {
// present in the backend/Jinja2 templates.
settings_display.set_default_language_name(event.language_name);
}
if (
event.property === "default_view" && // If current hash is empty (default view), and the
// user changes the default view while in settings,
// then going back to an empty hash on closing the
// overlay will not match the view currently displayed
// under settings, so we set the hash to the previous
// value of the default view.
!browser_history.state.hash_before_overlay &&
overlays.settings_open()
) {
browser_history.state.hash_before_overlay =
"#" +
(original_default_view === "recent_topics" ? "recent" : original_default_view);
}
if (event.property === "twenty_four_hour_time") {
// Rerender the whole message list UI
for (const msg_list of message_lists.all_rendered_message_lists()) {