Fix scroll restoration

This commit is contained in:
1ilit 2024-02-26 13:17:20 +02:00
parent 03cdd8eef0
commit d798a1fca9
3 changed files with 23 additions and 13 deletions

View File

@ -1,26 +1,34 @@
import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; import { BrowserRouter, Routes, Route, useLocation } from "react-router-dom";
import Editor from "./pages/Editor"; import Editor from "./pages/Editor";
import Survey from "./pages/Survey"; import Survey from "./pages/Survey";
import BugReport from "./pages/BugReport"; import BugReport from "./pages/BugReport";
import Shortcuts from "./pages/Shortcuts"; import Shortcuts from "./pages/Shortcuts";
import Templates from "./pages/Templates"; import Templates from "./pages/Templates";
import Home from "./pages/Home"; import { useEffect } from "react";
import { CookiesProvider } from "react-cookie"; import LandingPage from "./pages/LandingPage";
const Wrapper = ({ children }) => {
const location = useLocation();
useEffect(() => {
window.scroll(0, 0);
}, [location.pathname]);
return children;
};
function App() { function App() {
return ( return (
<CookiesProvider> <BrowserRouter>
<Router> <Wrapper>
<Routes> <Routes>
<Route path="/" element={<Home />} /> <Route path="/" element={<LandingPage />} />
<Route path="/editor" element={<Editor />} /> <Route path="/editor" element={<Editor />} />
<Route path="/survey" element={<Survey />} /> <Route path="/survey" element={<Survey />} />
<Route path="/shortcuts" element={<Shortcuts />} /> <Route path="/shortcuts" element={<Shortcuts />} />
<Route path="/bug_report" element={<BugReport />} /> <Route path="/bug_report" element={<BugReport />} />
<Route path="/templates" element={<Templates />} /> <Route path="/templates" element={<Templates />} />
</Routes> </Routes>
</Router> </Wrapper>
</CookiesProvider> </BrowserRouter>
); );
} }

View File

@ -571,7 +571,7 @@ export default function Editor() {
useEffect(() => { useEffect(() => {
document.title = "Editor | drawDB"; document.title = "Editor | drawDB";
const loadLatestDiagram = () => { const loadLatestDiagram = async () => {
db.diagrams db.diagrams
.orderBy("lastModified") .orderBy("lastModified")
.last() .last()
@ -595,7 +595,7 @@ export default function Editor() {
}); });
}; };
const loadDiagram = (id) => { const loadDiagram = async (id) => {
db.diagrams db.diagrams
.get(id) .get(id)
.then((diagram) => { .then((diagram) => {
@ -625,7 +625,7 @@ export default function Editor() {
}); });
}; };
const loadTemplate = (id) => { const loadTemplate = async (id) => {
db.templates db.templates
.get(id) .get(id)
.then((diagram) => { .then((diagram) => {

View File

@ -236,6 +236,8 @@ function SurveyForm({ theme }) {
export default function Survey() { export default function Survey() {
const [theme, setTheme] = useState(""); const [theme, setTheme] = useState("");
useEffect(() => window.scroll(0, 0));
useEffect(() => { useEffect(() => {
const t = localStorage.getItem("theme"); const t = localStorage.getItem("theme");
setTheme(t); setTheme(t);
@ -271,7 +273,7 @@ export default function Survey() {
}; };
return ( return (
<> <div>
<div className="sm:py-3 py-5 md:px-8 px-20 flex justify-between items-center"> <div className="sm:py-3 py-5 md:px-8 px-20 flex justify-between items-center">
<div className="flex items-center justify-start"> <div className="flex items-center justify-start">
<Link to="/"> <Link to="/">
@ -329,6 +331,6 @@ export default function Survey() {
<div className="text-center text-sm py-3"> <div className="text-center text-sm py-3">
&copy; 2024 <strong>drawDB</strong> - All right reserved. &copy; 2024 <strong>drawDB</strong> - All right reserved.
</div> </div>
</> </div>
); );
} }