diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.js index 7b260b9740..e91dc18b7d 100644 --- a/frontend_tests/node_tests/hotkey.js +++ b/frontend_tests/node_tests/hotkey.js @@ -227,7 +227,7 @@ run_test('basic_chars', () => { overlays.is_active = return_true; assert_mapping('S', 'subs.keyboard_sub'); assert_mapping('V', 'subs.view_stream'); - assert_mapping('n', 'subs.new_stream_clicked'); + assert_mapping('n', 'subs.open_create_stream'); page_params.can_create_streams = false; assert_unmapped('n'); overlays.streams_open = return_false; diff --git a/static/js/hotkey.js b/static/js/hotkey.js index 2fcd2d5e13..e550911575 100644 --- a/static/js/hotkey.js +++ b/static/js/hotkey.js @@ -613,7 +613,7 @@ exports.process_hotkey = function (e, hotkey) { return true; } if (event_name === 'n_key' && overlays.streams_open() && page_params.can_create_streams) { - subs.new_stream_clicked(); + subs.open_create_stream(); return true; } return false; diff --git a/static/js/stream_create.js b/static/js/stream_create.js index b4667c2009..5d895e435c 100644 --- a/static/js/stream_create.js +++ b/static/js/stream_create.js @@ -234,11 +234,6 @@ exports.new_stream_clicked = function (stream_name) { if (window.innerWidth > 700) { $('#create_stream_name').focus(); } - - // change the hash to #streams/new to allow for linking and - // easy discovery. - - window.location.hash = "#streams/new"; }; function clear_error_display() { diff --git a/static/js/subs.js b/static/js/subs.js index 3be8e953e6..d07b9f11b9 100644 --- a/static/js/subs.js +++ b/static/js/subs.js @@ -609,7 +609,7 @@ exports.change_state = (function () { if (hash.arguments.length > 0) { // if in #streams/new form. if (hash.arguments[0] === "new") { - exports.new_stream_clicked(); + exports.do_open_create_stream(); } else if (hash.arguments[0] === "all") { maybe_select_tab("all-streams"); } else if (hash.arguments[0] === "subscribed") { @@ -772,7 +772,10 @@ function ajaxUnsubscribe(sub) { }); } -exports.new_stream_clicked = function () { +exports.do_open_create_stream = function () { + // Only call this directly for hash changes. + // Prefer open_create_stream(). + var stream = $.trim($("#search_stream_name").val()); if (!should_list_all_streams()) { @@ -785,6 +788,16 @@ exports.new_stream_clicked = function () { stream_create.new_stream_clicked(stream); }; +exports.open_create_stream = function () { + exports.do_open_create_stream(); + + // this will change the hash which will attempt to retrigger the create + // stream code, so we prevent this once. + exports.change_state.prevent_once(); + window.location.hash = "#streams/new"; +}; + + exports.sub_or_unsub = function (sub) { if (sub.subscribed) { ajaxUnsubscribe(sub); @@ -806,10 +819,7 @@ exports.initialize = function () { $("#subscriptions_table").on("click", ".create_stream_button", function (e) { e.preventDefault(); - exports.new_stream_clicked(); - // this will change the hash which will attempt to retrigger the create - // stream code, so we prevent this once. - exports.change_state.prevent_once(); + exports.open_create_stream(); }); $(".subscriptions").on("click", "[data-dismiss]", function (e) {