Skip to content

Commit a4d113d

Browse files
authored
Merge pull request #195 from MeshJS/feature/UX-info-page
2 parents c79b3ef + c432f57 commit a4d113d

File tree

4 files changed

+863
-502
lines changed

4 files changed

+863
-502
lines changed

src/components/common/overall-layout/layout.tsx

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,56 @@ class WalletErrorBoundary extends Component<
7676
}
7777
}
7878

79+
// Component to track layout content changes
80+
function LayoutContentTracker({
81+
children,
82+
router,
83+
pageIsPublic,
84+
userAddress
85+
}: {
86+
children: ReactNode;
87+
router: ReturnType<typeof useRouter>;
88+
pageIsPublic: boolean;
89+
userAddress: string | undefined;
90+
}) {
91+
const prevPathRef = useRef<string>(router.pathname);
92+
const prevQueryRef = useRef<string>(JSON.stringify(router.query));
93+
94+
useEffect(() => {
95+
const handleRouteChangeStart = (url: string) => {
96+
// Route change started
97+
};
98+
99+
const handleRouteChangeComplete = (url: string) => {
100+
prevPathRef.current = router.pathname;
101+
prevQueryRef.current = JSON.stringify(router.query);
102+
};
103+
104+
const handleRouteChangeError = (err: Error, url: string) => {
105+
// Route change error
106+
};
107+
108+
router.events.on('routeChangeStart', handleRouteChangeStart);
109+
router.events.on('routeChangeComplete', handleRouteChangeComplete);
110+
router.events.on('routeChangeError', handleRouteChangeError);
111+
112+
return () => {
113+
router.events.off('routeChangeStart', handleRouteChangeStart);
114+
router.events.off('routeChangeComplete', handleRouteChangeComplete);
115+
router.events.off('routeChangeError', handleRouteChangeError);
116+
};
117+
}, [router]);
118+
119+
useEffect(() => {
120+
if (router.pathname !== prevPathRef.current || JSON.stringify(router.query) !== prevQueryRef.current) {
121+
prevPathRef.current = router.pathname;
122+
prevQueryRef.current = JSON.stringify(router.query);
123+
}
124+
}, [router.pathname, router.query]);
125+
126+
return <>{children}</>;
127+
}
128+
79129
export default function RootLayout({
80130
children,
81131
}: {
@@ -631,7 +681,9 @@ export default function RootLayout({
631681
</div>
632682
}
633683
>
634-
{pageIsPublic || userAddress ? children : <PageHomepage />}
684+
<LayoutContentTracker router={router} pageIsPublic={pageIsPublic} userAddress={userAddress}>
685+
{pageIsPublic || userAddress ? children : <PageHomepage />}
686+
</LayoutContentTracker>
635687
</WalletErrorBoundary>
636688
</main>
637689
</div>

0 commit comments

Comments
 (0)