Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

mainAppLocation.ts

29 lines793 Bytes

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 );
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;
25​
26export function useNavigateToMainApp() {
27 const navigate = useNavigate();
28 return () => navigate({ href: mainAppHref ?? "/" });