mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
When a user visits a direct video link (e.g. `/?v=...`) while logged in, the application auto-authenticates and redirects the view to `#view=for-you`. Previously, `setHashView` unconditionally removed all query parameters, causing the video modal to fail to open because the `v` parameter was lost before it could be read. This change: 1. Updates `setHashView` to accept an options object, allowing specific parameters to be preserved. 2. Updates `handleAuthLogin` in `app.js` to detect if a `v` parameter is present and request its preservation during the view switch.
36 lines
899 B
JavaScript
36 lines
899 B
JavaScript
// 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, options = {}) {
|
|
if (typeof window === "undefined") {
|
|
return;
|
|
}
|
|
|
|
const url = new URL(window.location.href);
|
|
url.searchParams.delete("modal");
|
|
if (!options?.preserveVideoParam) {
|
|
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"));
|
|
}
|
|
}
|