Merge pull request #1354 from PR0M3TH3AN/codex/implement-auth-event-handlers-for-navigation

Adjust auth-driven view routing
This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2026-01-18 20:32:04 -05:00
commit bc0ca62b64
4 files changed
+51 -18

No files matched your search

+16
View File
@@ -111,6 +111,7 @@ import {
syncActiveVideoRootTimestamp,
} from "./utils/videoTimestamps.js";
import { getDesignSystemMode as getCanonicalDesignSystemMode } from "./designSystem.js";
import { getHashViewName, setHashView } from "./hashView.js";
import {
getPubkey as getStoredPubkey,
setPubkey as setStoredPubkey,
@@ -4117,6 +4118,13 @@ class Application {
this.applyAuthenticatedUiState();
this.commentController?.refreshAuthState?.();
const currentView = getHashViewName();
const normalizedView =
typeof currentView === "string" ? currentView.toLowerCase() : "";
if (!normalizedView || normalizedView === "most-recent-videos") {
setHashView("for-you");
}
const rawProviderId =
typeof detail?.providerId === "string" ? detail.providerId.trim() : "";
const rawAuthType =
@@ -4362,6 +4370,14 @@ class Application {
this.applyLoggedOutUiState();
const logoutView = getHashViewName();
if (
typeof logoutView === "string" &&
logoutView.trim().toLowerCase() === "for-you"
) {
setHashView("most-recent-videos");
}
const activeModalVideo =
typeof this.videoModal?.getCurrentVideo === "function"
? this.videoModal.getCurrentVideo()
+33
View File
@@ -0,0 +1,33 @@
// js/hashView.js
const HASH_VIEW_REGEX = /^#view=([^&]+)/;
export function getHashViewName() {
const hash = typeof window !== "undefined" ? window.location.hash || "" : "";
const match = hash.match(HASH_VIEW_REGEX);
const viewName = match?.[1];
if (typeof viewName !== "string") {
return "";
}
return viewName.trim();
}
export function setHashView(viewName) {
if (typeof window === "undefined") {
return;
}
const url = new URL(window.location.href);
url.searchParams.delete("modal");
url.searchParams.delete("v");
const newUrl = url.pathname + url.search + `#view=${viewName}`;
window.history.replaceState({}, "", newUrl);
if (typeof HashChangeEvent === "function") {
window.dispatchEvent(new HashChangeEvent("hashchange"));
} else {
window.dispatchEvent(new Event("hashchange"));
}
}
+1 -17
View File
@@ -12,6 +12,7 @@ import {
initThemeController,
refreshThemeControls,
} from "./themeController.js";
import { setHashView } from "./hashView.js";
import { devLogger, userLogger } from "./utils/logger.js";
import {
prepareStaticModal,
@@ -1256,23 +1257,6 @@ if (document.readyState === "loading") {
HELPER FUNCTIONS FOR QUERY AND HASH
-------------------------------------------- */
/**
* Sets the location.hash to "#view=<viewName>",
* removing any ?modal=... or ?v=... from the query string.
*/
export function setHashView(viewName) {
const url = new URL(window.location.href);
url.searchParams.delete("modal");
url.searchParams.delete("v");
const newUrl = url.pathname + url.search + `#view=${viewName}`;
window.history.replaceState({}, "", newUrl);
if (typeof viewName === "string" && viewName.toLowerCase() === "history") {
}
handleHashChange();
}
/**
* Sets a query param (e.g. ?modal=xxx or ?v=yyy),
* removing any "#view=..." from the hash to avoid collisions.
+1 -1
View File
@@ -1,5 +1,5 @@
// sidebar.js
import { setHashView } from "./index.js";
import { setHashView } from "./hashView.js";
export function setupSidebarNavigation() {
const sidebarLinks = document.querySelectorAll('#sidebar a[href^="#view="]');