fix: fix switching to dashboard from analytics not working

This commit is contained in:
Jones Jankovic committed 2026-11-03 19:30:33 +10:30
1 parent f4ff4093d4
commit 998be36575
4 files changed
+26 -25

No files matched your search

@@ -18,6 +18,8 @@ const ANALYTICS_MENU_ICON = pageIcon("analytics")!;
export const ANALYTICS_MENU_CLASS = "betterseqta-grade-analytics-item";
export const ANALYTICS_MENU_KEY = "analytics";
export const isAnalyticsRoute = () => location.hash.startsWith("#?page=/analytics");
function loadAnalyticsPageLazy() {
void import("./loadAnalyticsPage").then((m) => m.loadAnalyticsPage());
}
@@ -96,8 +98,7 @@ export async function injectAnalyticsMenuItem(): Promise<() => void> {
) {
return;
}
e.preventDefault();
window.history.pushState({}, "", "/#?page=/analytics");
if (!isAnalyticsRoute()) location.hash = "?page=/analytics";
loadAnalyticsPageLazy();
};
analyticsItem.addEventListener("click", onClick);
@@ -106,5 +107,6 @@ export async function injectAnalyticsMenuItem(): Promise<() => void> {
menuObserver.disconnect();
analyticsItem.removeEventListener("click", onClick);
analyticsItem.remove();
if (isAnalyticsRoute()) void import("./ui").then((m) => m.unmountAnalyticsPage());
};
}
@@ -39,9 +39,6 @@ async function loadAnalyticsPageInner(): Promise<void> {
}
main.innerHTML = "";
main.style.overflow = "auto";
main.style.width = "100%";
main.style.maxWidth = "none";
const viewShell = document.createElement("div");
viewShell.id = "analytics-view-container";
main.appendChild(viewShell);
+18 -15
View File
@@ -6,6 +6,7 @@ import { mount, unmount } from "svelte";
import GradeAnalyticsPage from "./GradeAnalyticsPage.svelte";
import { buildContrastAccentPalette } from "./utils/accentColor";
import { extractSolidColor } from "@/seqta/ui/colors/parseCssColor";
import { isAnalyticsRoute } from "./injectAnalyticsMenuItem";
type ThemeSettingKey =
| "selectedColor"
@@ -23,18 +24,22 @@ type ThemeListenerRegistration = {
let currentApp: ReturnType<typeof mount> | null = null;
let shadowHost: HTMLElement | null = null;
let analyticsRoot: HTMLElement | null = null;
let darkModeObserver: MutationObserver | null = null;
let themeStyleObserver: MutationObserver | null = null;
let themeListeners: ThemeListenerRegistration[] = [];
const ANALYTICS_STACKING_STYLE_ID = "bsplus-analytics-stacking-styles";
const ANALYTICS_PAGE_STYLE_ID = "bsplus-analytics-page-styles";
/** Light-DOM stacking scope so toolbar/dropdown z-index cannot paint over ExtensionPopup. */
function ensureAnalyticsStackingScope() {
if (document.getElementById(ANALYTICS_STACKING_STYLE_ID)) return;
/** Light-DOM styles: stacking scope below ExtensionPopup, and #main sizing only while Analytics is shown. */
function ensureAnalyticsPageStyles() {
if (document.getElementById(ANALYTICS_PAGE_STYLE_ID)) return;
const style = document.createElement("style");
style.id = ANALYTICS_STACKING_STYLE_ID;
style.id = ANALYTICS_PAGE_STYLE_ID;
style.textContent = `
#main:has(> #analytics-view-container) {
overflow: auto;
width: 100%;
max-width: none;
}
#analytics-view-container,
.bsplus-analytics-container,
.bsplus-analytics-host {
@@ -159,7 +164,12 @@ function watchThemeChanges() {
});
}
function onRouteChange() {
if (!isAnalyticsRoute()) teardown();
}
function teardown() {
window.removeEventListener("hashchange", onRouteChange);
clearThemeListeners();
themeStyleObserver?.disconnect();
themeStyleObserver = null;
@@ -168,8 +178,6 @@ function teardown() {
unmount(currentApp);
currentApp = null;
}
darkModeObserver?.disconnect();
darkModeObserver = null;
shadowHost?.remove();
shadowHost = null;
analyticsRoot = null;
@@ -178,7 +186,8 @@ function teardown() {
export function renderAnalyticsPage(container: HTMLElement) {
teardown();
ensureAnalyticsStackingScope();
ensureAnalyticsPageStyles();
window.addEventListener("hashchange", onRouteChange);
container.innerHTML = "";
container.className = "bsplus-analytics-container";
@@ -200,12 +209,6 @@ export function renderAnalyticsPage(container: HTMLElement) {
watchThemeChanges();
darkModeObserver = new MutationObserver(() => syncThemeToAnalyticsUi());
darkModeObserver.observe(document.documentElement, {
attributes: true,
attributeFilter: ["class"],
});
currentApp = mount(GradeAnalyticsPage, {
target: analyticsRoot,
props: { simpleMode: isSimpleAnalyticsUi() },
+4 -5
View File
@@ -396,12 +396,11 @@ async function handleDashboard(node: Element): Promise<void> {
if (!animationsEnabled() || !fullMotionEffectsEnabled()) return;
const style = document.createElement("style");
style.classList.add("dashboardHider");
style.innerHTML = ".dashboard{opacity: 0 !important;}";
style.textContent = ".dashboard{opacity: 0 !important;}";
document.head.append(style);
await waitForElm(".dashlet", true, 10);
try {
await waitForElm(".dashlet", true, 10, 300);
const children = document.querySelectorAll(".dashboard > *");
if (children.length) {
const { animate, stagger } = await loadMotion();
@@ -417,9 +416,9 @@ async function handleDashboard(node: Element): Promise<void> {
}
} catch {
// Avoid uncaught errors if motion hits an unexpected DOM state during load.
} finally {
style.remove();
}
document.head.querySelector("style.dashboardHider")?.remove();
}
async function handleDocuments(node: Element): Promise<void> {