Skip to content

Commit

Permalink
hashchange: Go through hashchange to narrow to All messsages.
Browse files Browse the repository at this point in the history
We should not allow every function who wants to narrow to All
messages to come up with their own method to do so. This
commit makes existing such functions use hashchange library to
do so.

Remove click event on All message button, it already contains
an <a> tag which navigates correctly.
  • Loading branch information
amanagr authored and timabbott committed Jul 28, 2020
1 parent 8b29c38 commit 0859a91
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
4 changes: 4 additions & 0 deletions frontend_tests/node_tests/hashchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ zrequire("people");
zrequire("hash_util");
zrequire("hashchange");
zrequire("stream_data");
zrequire("navigate");

set_global("search", {
update_button_visibility: () => {},
});
set_global("document", "document-stub");
set_global("history", {});

Expand Down
10 changes: 0 additions & 10 deletions static/js/click_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,16 +569,6 @@ exports.initialize = function () {

// HOME

$(document).on("click", ".top_left_all_messages", (e) => {
ui_util.change_tab_to("#home");
narrow.deactivate();
search.update_button_visibility();
// We need to maybe scroll to the selected message
// once we have the proper viewport set up
setTimeout(navigate.maybe_scroll_to_selected, 0);
e.preventDefault();
});

$(".brand").on("click", (e) => {
if (overlays.is_active()) {
overlays.close_active();
Expand Down
4 changes: 4 additions & 0 deletions static/js/hashchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ function activate_home_tab() {
ui_util.change_tab_to("#home");
narrow.deactivate();
floating_recipient_bar.update();
search.update_button_visibility();
// We need to maybe scroll to the selected message
// once we have the proper viewport set up
setTimeout(navigate.maybe_scroll_to_selected, 0);
}

const state = {
Expand Down
2 changes: 1 addition & 1 deletion static/js/hotkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ exports.process_escape_key = function (e) {
return true;
}

narrow.deactivate();
hashchange.go_to_location("");
return true;
};

Expand Down
3 changes: 3 additions & 0 deletions static/js/narrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,9 @@ function handle_post_narrow_deactivate_processes() {
}

exports.deactivate = function () {
// NOTE: Never call this function independently,
// always use hashchange.go_to_location("") to
// activate All message narrow.
/*
Switches current_msg_list from narrowed_msg_list to
home_msg_list ("All messages"), ending the current narrow. This
Expand Down
3 changes: 1 addition & 2 deletions static/js/search_pill_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ exports.initialize = function () {

exports.widget.onPillRemove(() => {
if (exports.widget.items().length === 0) {
ui_util.change_tab_to("#home");
narrow.deactivate();
hashchange.go_to_location("");
}
});

Expand Down

0 comments on commit 0859a91

Please sign in to comment.