Open History to see the last commit
1import { useLocation, useNavigate } from "@tanstack/react-router";
2import { useEffect } from "react";
3
4export function isSidebarUtilityPage(pathname: string) {
5 return (
6 pathname === "/settings" ||
7 pathname.startsWith("/settings/") ||
8 pathname.startsWith("/projects/") ||
9 pathname === "/usage" ||
10 pathname === "/pull-requests"
11 );
12}
13
14let mainAppHref: string | null = null;
15
16export function MainAppLocationTracker() {
17 const href = useLocation({
18 select: (location) => (isSidebarUtilityPage(location.pathname) ? null : location.href),
19 });
20 useEffect(() => {
21 if (href !== null) mainAppHref = href;
22 }, [href]);
23 return null;
24}
25
26export function useNavigateToMainApp() {
27 const navigate = useNavigate();
28 return () => navigate({ href: mainAppHref ?? "/" });
29}