mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-03 19:35:28 +00:00
Wait for app initialization before handling hash views
This commit is contained in:
1 parent
9c7884d4b7
commit
9309ac11ea
2 files changed
+46
-26
No files matched your search
@@ -10853,5 +10853,6 @@ function dedupeToNewestByRoot(videos) {
|
||||
}
|
||||
|
||||
export const app = new bitvidApp();
|
||||
app.init();
|
||||
export const appReady = app.init();
|
||||
window.app = app;
|
||||
window.appReady = appReady;
|
||||
+44
-25
@@ -362,37 +362,56 @@ function handleQueryParams() {
|
||||
}
|
||||
}
|
||||
|
||||
function handleHashChange() {
|
||||
async function waitForAppInitialization() {
|
||||
const maybePromise = window.appReady;
|
||||
|
||||
if (!maybePromise || typeof maybePromise.then !== "function") {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await maybePromise;
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
"Proceeding with hash handling despite app initialization failure:",
|
||||
error
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleHashChange() {
|
||||
console.log("handleHashChange called, current hash =", window.location.hash);
|
||||
|
||||
await waitForAppInitialization();
|
||||
|
||||
const hash = window.location.hash || "";
|
||||
// Use a regex that captures up to the first ampersand or end of string.
|
||||
// E.g. "#view=channel-profile&npub=..." => viewName = "channel-profile"
|
||||
const match = hash.match(/^#view=([^&]+)/);
|
||||
|
||||
if (!match || !match[1]) {
|
||||
// No valid "#view=..." => default to "most-recent-videos"
|
||||
import("./viewManager.js").then(({ loadView, viewInitRegistry }) => {
|
||||
loadView("views/most-recent-videos.html").then(() => {
|
||||
const initFn = viewInitRegistry["most-recent-videos"];
|
||||
if (typeof initFn === "function") {
|
||||
initFn();
|
||||
}
|
||||
});
|
||||
});
|
||||
return;
|
||||
try {
|
||||
const { loadView, viewInitRegistry } = await import("./viewManager.js");
|
||||
|
||||
if (!match || !match[1]) {
|
||||
// No valid "#view=..." => default to "most-recent-videos"
|
||||
await loadView("views/most-recent-videos.html");
|
||||
const initFn = viewInitRegistry["most-recent-videos"];
|
||||
if (typeof initFn === "function") {
|
||||
initFn();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const viewName = match[1]; // only the chunk before any '&'
|
||||
const viewUrl = `views/${viewName}.html`;
|
||||
|
||||
// Now dynamically load that partial, then call its init function
|
||||
await loadView(viewUrl);
|
||||
const initFn = viewInitRegistry[viewName];
|
||||
if (typeof initFn === "function") {
|
||||
initFn();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to handle hash change:", error);
|
||||
}
|
||||
|
||||
const viewName = match[1]; // only the chunk before any '&'
|
||||
const viewUrl = `views/${viewName}.html`;
|
||||
|
||||
// Now dynamically load that partial, then call its init function
|
||||
import("./viewManager.js").then(({ loadView, viewInitRegistry }) => {
|
||||
loadView(viewUrl).then(() => {
|
||||
const initFn = viewInitRegistry[viewName];
|
||||
if (typeof initFn === "function") {
|
||||
initFn();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user