spectators: Move build_login_link out of hash_util.ts.

This commit is contained in:
Tim Abbott
2023-10-01 12:54:23 -07:00
parent fd221efc68
commit 1aea88fac1
4 changed files with 17 additions and 18 deletions

View File

@@ -1,6 +1,5 @@
import * as internal_url from "../shared/src/internal_url"; import * as internal_url from "../shared/src/internal_url";
import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as sub_store from "./sub_store"; import * as sub_store from "./sub_store";
@@ -299,15 +298,3 @@ export function is_spectator_compatible(hash: string): boolean {
return web_public_allowed_hashes.includes(main_hash); return web_public_allowed_hashes.includes(main_hash);
} }
export function current_hash_as_next(): string {
return `next=/${encodeURIComponent(window.location.hash)}`;
}
export function build_login_link(): string {
let login_link = "/login/?" + current_hash_as_next();
if (page_params.development_environment) {
login_link = "/devlogin/?" + current_hash_as_next();
}
return login_link;
}

View File

@@ -1,9 +1,9 @@
import $ from "jquery"; import $ from "jquery";
import {media_breakpoints_num} from "./css_variables"; import {media_breakpoints_num} from "./css_variables";
import * as hash_util from "./hash_util";
import * as popovers from "./popovers"; import * as popovers from "./popovers";
import * as resize from "./resize"; import * as resize from "./resize";
import * as spectators from "./spectators";
export function hide_userlist_sidebar() { export function hide_userlist_sidebar() {
$(".app-main .column-right").removeClass("expanded"); $(".app-main .column-right").removeClass("expanded");
@@ -35,7 +35,7 @@ export function initialize() {
$("body").on("click", ".login_button", (e) => { $("body").on("click", ".login_button", (e) => {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
window.location.href = hash_util.build_login_link(); window.location.href = spectators.build_login_link();
}); });
$("#userlist-toggle-button").on("click", (e) => { $("#userlist-toggle-button").on("click", (e) => {

View File

@@ -10,14 +10,25 @@ import $ from "jquery";
import render_login_to_access_modal from "../templates/login_to_access.hbs"; import render_login_to_access_modal from "../templates/login_to_access.hbs";
import * as browser_history from "./browser_history"; import * as browser_history from "./browser_history";
import * as hash_util from "./hash_util";
import * as overlays from "./overlays"; import * as overlays from "./overlays";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
export function current_hash_as_next(): string {
return `next=/${encodeURIComponent(window.location.hash)}`;
}
export function build_login_link(): string {
let login_link = "/login/?" + current_hash_as_next();
if (page_params.development_environment) {
login_link = "/devlogin/?" + current_hash_as_next();
}
return login_link;
}
export function login_to_access(empty_narrow?: boolean): void { export function login_to_access(empty_narrow?: boolean): void {
// Hide all overlays, popover and go back to the previous hash if the // Hide all overlays, popover and go back to the previous hash if the
// hash has changed. // hash has changed.
const login_link = hash_util.build_login_link(); const login_link = build_login_link();
const realm_name = page_params.realm_name; const realm_name = page_params.realm_name;
$("body").append( $("body").append(

View File

@@ -8,6 +8,7 @@ const {run_test} = require("./lib/test");
const hash_util = zrequire("hash_util"); const hash_util = zrequire("hash_util");
const stream_data = zrequire("stream_data"); const stream_data = zrequire("stream_data");
const people = zrequire("people"); const people = zrequire("people");
const spectators = zrequire("spectators");
const hamlet = { const hamlet = {
user_id: 15, user_id: 15,
@@ -191,5 +192,5 @@ run_test("test_search_public_streams_notice_url", () => {
run_test("test_current_hash_as_next", () => { run_test("test_current_hash_as_next", () => {
window.location.hash = "#foo"; window.location.hash = "#foo";
assert.equal(hash_util.current_hash_as_next(), "next=/%23foo"); assert.equal(spectators.current_hash_as_next(), "next=/%23foo");
}); });