always scroll to top on route change, except on back nav
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Martti Malmi 2024-02-16 10:27:54 +02:00
parent 73753c2764
commit 86906682f9
5 changed files with 10 additions and 6 deletions

View File

@ -225,7 +225,6 @@ export function ThreadRoute({ id }: { id?: string }) {
return (
<ThreadContextWrapper link={link}>
<ScrollToTop />
<Thread />
</ThreadContextWrapper>
);

View File

@ -1,12 +1,16 @@
import { useEffect } from "react";
import { useLocation } from "react-router-dom";
import { useLocation, useNavigationType } from "react-router-dom";
export default function ScrollToTop() {
const { pathname } = useLocation();
const navigationType = useNavigationType(); // This hook is available in React Router v6
useEffect(() => {
window.scrollTo(0, 0);
}, [pathname]);
if (navigationType !== "POP") {
window.scrollTo(0, 0);
}
// Only scrolls to top on PUSH or REPLACE, not on POP
}, [pathname, navigationType]);
return null;
}

View File

@ -74,7 +74,7 @@ const getNavLinkClass = (isActive: boolean, narrow: boolean) => {
});
};
export default function NavSidebar({ narrow = false }: { narrow: boolean }) {
export default function NavSidebar({ narrow = false }: { narrow?: boolean }) {
const { publicKey, readonly } = useLogin(s => ({
publicKey: s.publicKey,
readonly: s.readonly,

View File

@ -20,6 +20,7 @@ import { LoginStore } from "@/Utils/Login";
import NavSidebar from "./NavSidebar";
import RightColumn from "./RightColumn";
import ScrollToTop from "@/Components/ScrollToTop";
export default function Index() {
const location = useLocation();
@ -57,6 +58,7 @@ export default function Index() {
return (
<ErrorBoundary>
<ScrollToTop />
<div className="flex justify-center">
<div className="w-full max-w-screen-xl">
<div className="flex flex-row">

View File

@ -53,7 +53,6 @@ export default function NotificationsPage({ onClick }: { onClick?: (link: NostrL
return (
<>
<ScrollToTop />
<div className="main-content">
{CONFIG.features.notificationGraph && (
<Suspense fallback={<PageSpinner />}>