From c9dbe1e3e7ff1e852749a304b0d80c1034184337 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Sun, 18 Jan 2026 20:31:30 -0500 Subject: [PATCH] Adjust auth-driven view routing --- js/app.js | 16 ++++++++++++++++ js/hashView.js | 33 +++++++++++++++++++++++++++++++++ js/index.js | 18 +----------------- js/sidebar.js | 2 +- 4 files changed, 51 insertions(+), 18 deletions(-) create mode 100644 js/hashView.js diff --git a/js/app.js b/js/app.js index 78039277..61afb2f6 100644 --- a/js/app.js +++ b/js/app.js @@ -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() diff --git a/js/hashView.js b/js/hashView.js new file mode 100644 index 00000000..e900f612 --- /dev/null +++ b/js/hashView.js @@ -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")); + } +} diff --git a/js/index.js b/js/index.js index ab420c28..cbe8f39b 100644 --- a/js/index.js +++ b/js/index.js @@ -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=", - * 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. diff --git a/js/sidebar.js b/js/sidebar.js index 36a74fc9..e11106ea 100644 --- a/js/sidebar.js +++ b/js/sidebar.js @@ -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="]');