left sidebar: Make sure the selected stream is visible in left sidebar.

This triggers a scroll in the left sidebar after an initial narrow if
the target stream isn't visible.

Fixes #9043.
This commit is contained in:
Cynthia Lin
2018-07-06 11:23:20 -07:00
committed by Tim Abbott
parent 66df4e3e84
commit c3b1381c2a
3 changed files with 44 additions and 1 deletions

View File

@@ -28,7 +28,9 @@ set_global('narrow_state', {});
set_global('pm_list', {}); set_global('pm_list', {});
set_global('resize', {}); set_global('resize', {});
set_global('server_events', {}); set_global('server_events', {});
set_global('stream_list', {}); set_global('stream_list', {
maybe_scroll_narrow_into_view: () => {},
});
muting.is_topic_muted = function () { return false; }; muting.is_topic_muted = function () { return false; };
resize.resize_bottom_whitespace = noop; resize.resize_bottom_whitespace = noop;

View File

@@ -51,6 +51,7 @@ function process_result(data, opts) {
activity.process_loaded_messages(messages); activity.process_loaded_messages(messages);
stream_list.update_streams_sidebar(); stream_list.update_streams_sidebar();
pm_list.update_private_messages(); pm_list.update_private_messages();
stream_list.maybe_scroll_narrow_into_view();
if (opts.cont !== undefined) { if (opts.cont !== undefined) {
opts.cont(data); opts.cont(data);

View File

@@ -2,6 +2,8 @@ var stream_list = (function () {
var exports = {}; var exports = {};
var has_scrolled = false;
exports.update_count_in_dom = function (unread_count_elem, count) { exports.update_count_in_dom = function (unread_count_elem, count) {
var count_span = unread_count_elem.find('.count'); var count_span = unread_count_elem.find('.count');
var value_span = count_span.find('.value'); var value_span = count_span.find('.value');
@@ -523,6 +525,13 @@ exports.initialize = function () {
exports.toggle_filter_displayed(e); exports.toggle_filter_displayed(e);
}); });
// check for user scrolls on streams list for first time
$('#stream-filters-container').on('scroll', function () {
has_scrolled = true;
// remove listener once user has scrolled
$(this).off('scroll');
});
exports.stream_cursor = list_cursor({ exports.stream_cursor = list_cursor({
list: { list: {
container: $('#stream-filters-container'), container: $('#stream-filters-container'),
@@ -631,6 +640,37 @@ exports.scroll_stream_into_view = function (stream_li) {
scroll_util.scroll_element_into_container(stream_li, container); scroll_util.scroll_element_into_container(stream_li, container);
}; };
exports.maybe_scroll_narrow_into_view = function () {
// we don't want to interfere with user scrolling once the page loads
if (has_scrolled) {
return;
}
var stream_li = stream_list.get_current_stream_li();
if (stream_li) {
stream_list.scroll_stream_into_view(stream_li);
}
};
exports.get_current_stream_li = function () {
var stream_id = topic_list.active_stream_id();
if (!stream_id) {
// stream_id is undefined in non-stream narrows
return;
}
var stream_li = stream_list.get_stream_li(stream_id);
if (!stream_li) {
// This code path shouldn't ever be reached.
blueslip.warn('No active stream_li found for defined id ' + stream_id);
return;
}
return stream_li;
};
return exports; return exports;
}()); }());
if (typeof module !== 'undefined') { if (typeof module !== 'undefined') {