11import { ArrowLeftIcon , ChartNoAxesColumnIcon , SettingsIcon } from "lucide-react" ;
22import type { ReactNode } from "react" ;
33import { memo , useCallback } from "react" ;
4- import { Link , useCanGoBack , useLocation , useNavigate } from "@tanstack/react-router" ;
4+ import { Link , useLocation , useNavigate } from "@tanstack/react-router" ;
55
66import { useEnvironmentIdentificationMode } from "../../hooks/useSettings" ;
77import { cn } from "../../lib/utils" ;
@@ -24,6 +24,7 @@ import {
2424} from "../ui/sidebar" ;
2525import { Tooltip , TooltipPopup , TooltipTrigger } from "../ui/tooltip" ;
2626import { readPullRequestListPreferences } from "../pullRequest/pullRequestListPreferences" ;
27+ import { isSidebarUtilityPage , useNavigateToMainApp } from "./mainAppLocation" ;
2728import { SidebarThreadUndoNotice } from "./SidebarThreadUndoNotice" ;
2829import { SidebarProviderUpdatePill } from "./SidebarProviderUpdatePill" ;
2930import { SidebarUpdateArchitectureWarning , SidebarUpdatePill } from "./SidebarUpdatePill" ;
@@ -127,19 +128,10 @@ function SidebarUtilityItem({
127128
128129export const SidebarUtilityMenu = memo ( function SidebarUtilityMenu ( ) {
129130 const navigate = useNavigate ( ) ;
130- const canGoBack = useCanGoBack ( ) ;
131+ const navigateToMainApp = useNavigateToMainApp ( ) ;
131132 const { isMobile, setOpenMobile } = useSidebar ( ) ;
132- const currentFooterPage = useLocation ( {
133- select : ( location ) =>
134- / ^ \/ s e t t i n g s (?: \/ | $ ) / . test ( location . pathname )
135- ? "settings"
136- : / ^ \/ p r o j e c t s \/ [ ^ / ] + \/ ? $ / . test ( location . pathname )
137- ? "project-settings"
138- : location . pathname === "/usage"
139- ? "usage"
140- : location . pathname === "/pull-requests"
141- ? "pull-requests"
142- : null ,
133+ const isOnUtilityPage = useLocation ( {
134+ select : ( location ) => isSidebarUtilityPage ( location . pathname ) ,
143135 } ) ;
144136 const { environments } = useEnvironments ( ) ;
145137 // The page reads every connected server, so one of them offering pull requests is enough for
@@ -173,16 +165,12 @@ export const SidebarUtilityMenu = memo(function SidebarUtilityMenu() {
173165
174166 const handleBackClick = useCallback ( ( ) => {
175167 closeMobileSidebar ( ) ;
176- if ( canGoBack ) {
177- window . history . back ( ) ;
178- return ;
179- }
180- void navigate ( { to : "/" } ) ;
181- } , [ canGoBack , closeMobileSidebar , navigate ] ) ;
168+ void navigateToMainApp ( ) ;
169+ } , [ closeMobileSidebar , navigateToMainApp ] ) ;
182170
183171 return (
184172 < SidebarMenu className = "flex-row items-center" >
185- { currentFooterPage ? (
173+ { isOnUtilityPage ? (
186174 < SidebarMenuItem className = "min-w-0 flex-1" >
187175 < SidebarMenuButton onClick = { handleBackClick } >
188176 < ArrowLeftIcon />
0 commit comments