Simplify stream sidebar narrows.

This fix simplifies how we re-render topic lists when we
re-narrow or zoom out from a topic list.

    * The topic_list.zoom_out() no longer gets called as
      part of re-narrowing, and we eliminate the clear_topics
      option.

    * For all situations where we narrow to a filter that does
      not have a topic, we simply call the new function
      clear_topics().

    * The stream_list code no longer calls remove_expanded_topics()
      in cases where the new narrow has a topic.  This allows us
      to optimize away scroll/flicker churn a little more easily.

As part of this, we rename maybe_activate_stream_item() to
update_stream_sidebar_for_narrow(), since the function clears
stuff as well as turning stuff on.
This commit is contained in:
Steve Howell 2017-08-10 18:30:23 -04:00 committed by Tim Abbott
parent 2146e17709
commit fad024ebda
3 changed files with 30 additions and 30 deletions

View File

@ -239,9 +239,11 @@ function initialize_stream_data() {
});
topic_list.set_click_handlers = noop;
topic_list.is_zoomed = return_false;
topic_list.close = noop;
topic_list.remove_expanded_topics = noop;
topic_list.rebuild = noop;
topic_list.active_stream_id = noop;
stream_list.show_all_streams = noop;
stream_list.scroll_element_into_container = noop;
var scrollbar_updated = false;

View File

@ -180,7 +180,7 @@ function zoom_in() {
function zoom_out(options) {
popovers.hide_all();
topic_list.zoom_out(options);
topic_list.zoom_out();
if (options.stream_li) {
exports.scroll_stream_into_view(options.stream_li);
@ -201,14 +201,6 @@ exports.show_all_streams = function () {
$("#stream_filters li.narrow-filter").show();
};
function reset_to_unnarrowed(narrowed_within_same_stream) {
if (topic_list.is_zoomed() && narrowed_within_same_stream !== true) {
zoom_out({clear_topics: true});
} else {
topic_list.remove_expanded_topics();
}
}
exports.set_in_home_view = function (stream_id, in_home) {
var li = exports.get_stream_li(stream_id);
if (!li) {
@ -317,7 +309,7 @@ exports.update_streams_sidebar = function () {
var filter = narrow_state.filter();
exports.maybe_activate_stream_item(filter);
exports.update_stream_sidebar_for_narrow(filter);
};
exports.update_dom_with_unread_counts = function (counts) {
@ -379,6 +371,11 @@ exports.refresh_pinned_or_unpinned_stream = function (sub) {
}
};
function clear_topics() {
topic_list.close();
exports.show_all_streams();
}
exports.get_sidebar_stream_topic_info = function (filter) {
var result = {
stream_id: undefined,
@ -409,12 +406,13 @@ exports.get_sidebar_stream_topic_info = function (filter) {
return result;
};
exports.maybe_activate_stream_item = function (filter) {
exports.update_stream_sidebar_for_narrow = function (filter) {
var info = exports.get_sidebar_stream_topic_info(filter);
var stream_id = info.stream_id;
if (!stream_id) {
clear_topics();
return;
}
@ -427,6 +425,7 @@ exports.maybe_activate_stream_item = function (filter) {
// evidence that this assumption breaks down for some users,
// but we are not clear why it happens.
blueslip.error('No stream_li for subscribed stream ' + stream_id);
clear_topics();
return;
}
@ -434,6 +433,10 @@ exports.maybe_activate_stream_item = function (filter) {
stream_li.addClass('active-filter');
}
if (stream_id !== topic_list.active_stream_id()) {
clear_topics();
}
topic_list.rebuild(stream_li, stream_id);
return stream_li;
@ -489,9 +492,7 @@ exports.initialize = function () {
$(document).on('narrow_activated.zulip', function (event) {
exports.update_top_left_corner_for_narrow(event.filter);
reset_to_unnarrowed(narrow_state.stream() === zoomed_stream);
var stream_li = exports.maybe_activate_stream_item(event.filter);
var stream_li = exports.update_stream_sidebar_for_narrow(event.filter);
if (stream_li) {
exports.scroll_stream_into_view(stream_li);
}
@ -501,7 +502,7 @@ exports.initialize = function () {
$(document).on('narrow_deactivated.zulip', function () {
deselect_top_left_corner_items();
reset_to_unnarrowed();
clear_topics();
pm_list.close();
var filter_li = exports.get_global_filter_li('home');

View File

@ -13,9 +13,20 @@ exports.remove_expanded_topics = function () {
if (active_widget) {
active_widget.remove();
active_widget = undefined;
}
};
exports.close = function () {
zoomed = false;
exports.remove_expanded_topics();
};
exports.zoom_out = function () {
zoomed = false;
exports.rebuild(active_widget.get_parent(), active_widget.get_stream_id());
};
function update_unread_count(unread_count_elem, count) {
// unread_count_elem is a jquery element...we expect DOM
// to look like this:
@ -198,19 +209,6 @@ exports.zoom_in = function () {
}
};
exports.zoom_out = function (options) {
zoomed = false;
if (options && options.clear_topics) {
exports.remove_expanded_topics();
} else {
exports.rebuild(active_widget.get_parent(), active_widget.get_stream_id());
}
};
exports.is_zoomed = function () {
return zoomed;
};
exports.set_click_handlers = function (callbacks) {
$('#stream_filters').on('click', '.show-more-topics', function (e) {
callbacks.zoom_in();
@ -221,7 +219,6 @@ exports.set_click_handlers = function (callbacks) {
$('.show-all-streams').on('click', function (e) {
callbacks.zoom_out({
clear_topics: false,
stream_li: active_widget.get_parent(),
});