mirror of https://github.com/zulip/zulip.git
hashchange: Pass in a "section" to subs.change_state.
We also eliminate get_hash_components() and clean up the code a bit in change_state().
This commit is contained in:
parent
a2fd901bec
commit
ead356971c
|
@ -65,15 +65,6 @@ var state = {
|
|||
old_hash: typeof window !== "undefined" ? window.location.hash : "#",
|
||||
};
|
||||
|
||||
function get_hash_components() {
|
||||
var hash = window.location.hash.split(/\//);
|
||||
|
||||
return {
|
||||
base: hash.shift(),
|
||||
arguments: hash,
|
||||
};
|
||||
}
|
||||
|
||||
function is_overlay_hash(hash) {
|
||||
// Hash changes within this list are overlays and should not unnarrow (etc.)
|
||||
var overlay_list = ["streams", "drafts", "settings", "organization", "invite"];
|
||||
|
@ -143,6 +134,7 @@ function do_hashchange_normal(from_reload) {
|
|||
function do_hashchange_overlay(old_hash) {
|
||||
var base = hash_util.get_hash_category(window.location.hash);
|
||||
var old_base = hash_util.get_hash_category(old_hash);
|
||||
var section = hash_util.get_hash_section(window.location.hash);
|
||||
|
||||
var coming_from_overlay = is_overlay_hash(old_hash || '#');
|
||||
|
||||
|
@ -154,7 +146,7 @@ function do_hashchange_overlay(old_hash) {
|
|||
if (coming_from_overlay) {
|
||||
if (base === old_base) {
|
||||
if (base === 'streams') {
|
||||
subs.change_state(get_hash_components());
|
||||
subs.change_state(section);
|
||||
}
|
||||
|
||||
// TODO: handle other cases like internal settings
|
||||
|
@ -178,7 +170,7 @@ function do_hashchange_overlay(old_hash) {
|
|||
}
|
||||
|
||||
if (base === "streams") {
|
||||
subs.launch(get_hash_components());
|
||||
subs.launch(section);
|
||||
} else if (base === "drafts") {
|
||||
drafts.launch();
|
||||
} else if (/settings|organization/.test(base)) {
|
||||
|
|
|
@ -579,35 +579,42 @@ exports.switch_to_stream_row = function (stream_id) {
|
|||
}, 100);
|
||||
};
|
||||
|
||||
exports.change_state = function (hash) {
|
||||
if (hash.arguments.length === 0) {
|
||||
exports.change_state = function (section) {
|
||||
// if in #streams/new form.
|
||||
if (section === "new") {
|
||||
exports.do_open_create_stream();
|
||||
return;
|
||||
}
|
||||
|
||||
var base = hash.arguments[0];
|
||||
|
||||
// if in #streams/new form.
|
||||
if (base === "new") {
|
||||
exports.do_open_create_stream();
|
||||
} else if (base === "all") {
|
||||
if (section === "all") {
|
||||
exports.toggler.goto('all-streams');
|
||||
} else if (base === "subscribed") {
|
||||
exports.toggler.goto('subscribed');
|
||||
// if the first argument is a valid number.
|
||||
} else if (/\d+/.test(base)) {
|
||||
var stream_id = base;
|
||||
exports.switch_to_stream_row(stream_id);
|
||||
return;
|
||||
}
|
||||
|
||||
if (section === "subscribed") {
|
||||
exports.toggler.goto('subscribed');
|
||||
return;
|
||||
}
|
||||
|
||||
// if the section is a valid number.
|
||||
if (/\d+/.test(section)) {
|
||||
var stream_id = section;
|
||||
exports.switch_to_stream_row(stream_id);
|
||||
return;
|
||||
}
|
||||
|
||||
blueslip.warn('invalid section for streams: ' + section);
|
||||
exports.toggler.goto('subscribed');
|
||||
};
|
||||
|
||||
exports.launch = function (hash) {
|
||||
exports.launch = function (section) {
|
||||
exports.setup_page(function () {
|
||||
overlays.open_overlay({
|
||||
name: 'subscriptions',
|
||||
overlay: $("#subscription_overlay"),
|
||||
on_close: exports.close,
|
||||
});
|
||||
exports.change_state(hash);
|
||||
exports.change_state(section);
|
||||
|
||||
ui.set_up_scrollbar($("#subscription_overlay .streams-list"));
|
||||
ui.set_up_scrollbar($("#subscription_overlay .settings"));
|
||||
|
|
Loading…
Reference in New Issue