修复&优化听力补偿模块功能
This commit is contained in:
+25
-3
@@ -1,7 +1,7 @@
|
||||
import { lazy, Suspense } from "react";
|
||||
import { lazy, Suspense, useEffect, useRef } from "react";
|
||||
import { Toaster } from "@/components/ui/sonner";
|
||||
import { TooltipProvider } from "@/components/ui/tooltip";
|
||||
import { Route, Switch, Router } from "wouter";
|
||||
import { Route, Switch, Router, useLocation } from "wouter";
|
||||
import { useHashLocation } from "wouter/use-hash-location";
|
||||
import ErrorBoundary from "./components/ErrorBoundary";
|
||||
import PageLoader from "./components/PageLoader";
|
||||
@@ -15,7 +15,7 @@ import BluetoothPage from "./pages/BluetoothPage";
|
||||
import SystemPage from "./pages/SystemPage";
|
||||
import IOPage from "./pages/IOPage";
|
||||
import VUPage from "./pages/VUPage";
|
||||
import SelectPage from "./pages/SelectPage";
|
||||
import SelectPage, { consumeSelectReturnScroll } from "./pages/SelectPage";
|
||||
import CommunityPage from "./pages/CommunityPage";
|
||||
import ChangelogPage from "./pages/ChangelogPage";
|
||||
import { AIDrawerProvider } from "./contexts/AIDrawerContext";
|
||||
@@ -54,6 +54,27 @@ function EffectsPageRoute() {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores the calling page's scroll position when returning from /select.
|
||||
* The select page is short, so the browser clamps window scroll to 0 while on
|
||||
* it; navigateToSelect() captures the offset before navigating and we re-apply
|
||||
* it once the calling page (e.g. Effects) has remounted.
|
||||
*/
|
||||
function SelectScrollRestore() {
|
||||
const [location] = useLocation();
|
||||
const prevRef = useRef(location);
|
||||
useEffect(() => {
|
||||
const prev = prevRef.current;
|
||||
prevRef.current = location;
|
||||
if (prev !== "/select" || location === "/select") return;
|
||||
const y = consumeSelectReturnScroll();
|
||||
if (y == null || y <= 0) return;
|
||||
// Wait a frame so the returning page has rendered and the document has height.
|
||||
requestAnimationFrame(() => window.scrollTo(0, y));
|
||||
}, [location]);
|
||||
return null;
|
||||
}
|
||||
|
||||
function AppRouter() {
|
||||
return (
|
||||
<Switch>
|
||||
@@ -85,6 +106,7 @@ function App() {
|
||||
<Toaster />
|
||||
<Router hook={useHashLocation}>
|
||||
<AIDrawerProvider>
|
||||
<SelectScrollRestore />
|
||||
<div className={appShellOuterClass}>
|
||||
<div className={appShellColumnClass}>
|
||||
<DesktopAIShell>
|
||||
|
||||
Reference in New Issue
Block a user